:root {
  --bg: #f8f4eb;
  --paper: #fffdf8;
  --paper-soft: #fff8ed;
  --ink: #142033;
  --muted: #6b7280;
  --line: #e8dcc9;
  --line-strong: #d6c5aa;
  --brand: #111827;
  --accent: #f97316;
  --accent-soft: #ffedd5;
  --ok: #d9f99d;
  --ok-ink: #31530c;
  --ng: #fecaca;
  --ng-ink: #7f1d1d;
  --maybe: #fde68a;
  --maybe-ink: #6b4e00;
  --ask: #bfdbfe;
  --ask-ink: #173d73;
  --blank: #fffdf8;
  --plan: #bae6fd;
  --plan-ink: #0c4a6e;
  --candidate: #ddd6fe;
  --candidate-ink: #3b2475;
  --hold: #fed7aa;
  --hold-ink: #7c2d12;
  --buffer: #e2e8f0;
  --buffer-ink: #334155;
  --deadline: #fbcfe8;
  --deadline-ink: #831843;
  --busy: #fecaca;
  --busy-ink: #7f1d1d;
  --window: #bbf7d0;
  --window-ink: #14532d;
  --shadow: 0 18px 46px rgba(20, 32, 51, 0.10);
  --radius: 24px;
  --row-height: 34px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(249, 115, 22, 0.14), transparent 30rem),
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.10), transparent 32rem),
    var(--bg);
}

button,
input,
select { font: inherit; }
button { cursor: pointer; }
input,
select,
button { min-width: 0; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(249, 115, 22, 0.45);
  outline-offset: 3px;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(1180px, calc(100% - 28px));
  margin: 14px auto 0;
  padding: 10px;
  border: 1px solid rgba(20, 32, 51, 0.08);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.84);
  box-shadow: 0 10px 30px rgba(20, 32, 51, 0.08);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-left: 4px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: #fff7ed;
  background: var(--brand);
  font-weight: 900;
  box-shadow: inset 0 -10px 24px rgba(249, 115, 22, 0.32);
}

.brand-copy {
  display: grid;
  min-width: 0;
  line-height: 1.1;
}
.brand-copy strong { font-size: 1.05rem; letter-spacing: 0.02em; }
.brand-copy small {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions,
.sub-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.main-button,
.quiet-button,
.file-button,
.icon-button,
.paint-button {
  border: 0;
  border-radius: 999px;
  font-weight: 850;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease, border-color 150ms ease;
}

.main-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  color: #fff7ed;
  background: linear-gradient(135deg, var(--brand), #27324a);
  box-shadow: 0 12px 26px rgba(17, 24, 39, 0.18);
  white-space: nowrap;
}

.soft-main {
  color: #7c2d12;
  background: linear-gradient(135deg, #ffedd5, #fed7aa);
  box-shadow: 0 10px 22px rgba(249, 115, 22, 0.18);
}

.quiet-button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(20, 32, 51, 0.10);
  white-space: nowrap;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: rgba(20, 32, 51, 0.05);
}

.main-button:hover,
.quiet-button:hover,
.file-button:hover,
.icon-button:hover,
.paint-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 30px rgba(20, 32, 51, 0.12);
}
.main-button:active,
.quiet-button:active,
.file-button:active,
.icon-button:active,
.paint-button:active { transform: translateY(0); }

.app {
  width: min(1180px, calc(100% - 28px));
  margin: 18px auto 32px;
}

.setup-card,
.calendar-card,
.object-panel {
  border: 1px solid rgba(20, 32, 51, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.setup-card {
  padding: 16px;
}

.setup-primary {
  display: grid;
  gap: 12px;
}

.scope-grid,
.secondary-grid,
.object-form {
  display: grid;
  gap: 10px;
  align-items: end;
  min-width: 0;
}

.scope-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
}
.secondary-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr));
  margin-top: 12px;
}
.object-form {
  grid-template-columns: 1.35fr minmax(130px, 0.75fr) repeat(3, minmax(105px, 0.62fr));
}

.field,
.mode-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span,
.mode-field legend {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.02em;
}

.field input,
.field select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf8;
}

.title-field input {
  font-size: 1.12rem;
  font-weight: 850;
}

.mode-field {
  margin: 0;
  padding: 0;
  border: 0;
}
.mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fffdf8;
}
.mode-options label {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 86px;
  gap: 6px;
  min-height: 32px;
  padding: 0 9px;
  border-radius: 12px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 850;
  white-space: nowrap;
}
.mode-options label:has(input:checked) {
  background: var(--accent-soft);
  color: #7c2d12;
}
.mode-options input { accent-color: var(--accent); }
.fit-button { width: 100%; }
.memo-field { grid-column: span 2; }

.thin-details {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.thin-details summary {
  width: fit-content;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 850;
  cursor: pointer;
}
.sub-actions { margin-top: 10px; }

.calendar-card {
  margin-top: 14px;
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid rgba(20, 32, 51, 0.07);
  background: linear-gradient(135deg, rgba(255, 248, 237, 0.95), rgba(255, 253, 248, 0.95));
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.preview-head h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.8vw, 2.2rem);
  letter-spacing: -0.04em;
}
.preview-memo {
  margin: 6px 0 0;
  color: var(--muted);
  font-weight: 650;
}
.summary-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}
.summary-chips span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(20, 32, 51, 0.08);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.72);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}

.tool-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: #fffdf8;
}
.paint-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}
.paint-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(20, 32, 51, 0.045);
  border: 1px solid transparent;
  white-space: nowrap;
}
.paint-button.active {
  border-color: rgba(20, 32, 51, 0.14);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.12);
}
.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 999px;
  border: 1px solid rgba(20, 32, 51, 0.16);
}
.dot.ok { background: var(--ok); }
.dot.ng { background: var(--ng); }
.dot.maybe { background: var(--maybe); }
.dot.ask { background: var(--ask); }
.dot.blank { background: var(--blank); }

.object-panel {
  margin: 0 18px 14px;
  padding: 14px;
  box-shadow: 0 12px 32px rgba(20, 32, 51, 0.08);
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.panel-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}
.object-title-field { grid-column: span 2; }
.object-note-field { grid-column: span 2; }
.ghost-field { display: none; }
.object-panel.show-ghost .ghost-field { display: grid; }

.object-list-wrap {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}
.object-list-wrap h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.86rem;
}
.object-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.object-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf8;
}
.object-list .empty {
  color: var(--muted);
  font-weight: 750;
}
.object-list button {
  border: 0;
  background: transparent;
  color: inherit;
}
.object-list .edit-object {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  text-align: left;
}
.object-list strong,
.object-list small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.object-list small {
  color: var(--muted);
  font-weight: 750;
}
.object-list .item-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}
.object-list .item-actions button {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(20, 32, 51, 0.05);
  font-size: 0.78rem;
  font-weight: 850;
}
.object-list .released {
  opacity: 0.5;
}

.calendar-scroller {
  overflow: auto;
  max-height: min(70vh, 780px);
  border-top: 1px solid rgba(20, 32, 51, 0.07);
  background: #fffaf1;
}
.calendar-grid {
  --days: 7;
  --rows: 20;
  --row-height: 34px;
  display: grid;
  grid-template-columns: 74px repeat(var(--days), minmax(136px, 1fr));
  grid-template-rows: 50px repeat(var(--rows), var(--row-height));
  min-width: calc(74px + var(--days) * 136px);
  position: relative;
}
.corner,
.day-head,
.time-cell,
.slot-cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.corner,
.day-head,
.time-cell {
  background: #fff7e6;
}
.corner,
.day-head {
  position: sticky;
  top: 0;
  z-index: 8;
}
.corner {
  left: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}
.day-head {
  display: grid;
  align-content: center;
  gap: 1px;
  padding: 0 10px;
}
.day-head strong {
  font-size: 0.96rem;
  letter-spacing: -0.02em;
}
.day-head span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}
.day-head.today {
  background: #eff6ff;
}
.time-cell {
  position: sticky;
  left: 0;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 7px 10px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}
.slot-cell {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  padding: 0;
  border-top: 0;
  border-left: 0;
  background: #fffdf8;
  color: rgba(20, 32, 51, 0.56);
  text-align: right;
  touch-action: none;
}
.slot-cell span {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.68rem;
  font-weight: 950;
  opacity: 0.72;
  pointer-events: none;
}
.slot-cell.state-ok { background: var(--ok); color: var(--ok-ink); }
.slot-cell.state-ng { background: var(--ng); color: var(--ng-ink); }
.slot-cell.state-maybe { background: var(--maybe); color: var(--maybe-ink); }
.slot-cell.state-ask { background: var(--ask); color: var(--ask-ink); }
.slot-cell.state-blank { background: #fffdf8; }
.slot-cell:hover {
  box-shadow: inset 0 0 0 2px rgba(249, 115, 22, 0.34);
}
.event-layer {
  position: relative;
  z-index: 5;
  pointer-events: none;
}
.event-block {
  position: absolute;
  left: 6px;
  width: calc(100% - 12px);
  min-height: 24px;
  overflow: hidden;
  border: 1.5px solid currentColor;
  border-radius: 13px;
  box-shadow: 0 8px 18px rgba(20, 32, 51, 0.12);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}
.event-block:active { cursor: grabbing; }
.event-block.dragging {
  opacity: 0.82;
  box-shadow: 0 18px 38px rgba(20, 32, 51, 0.20);
}
.event-block .block-inner {
  display: grid;
  gap: 2px;
  height: 100%;
  padding: 7px 8px 8px;
}
.event-block strong,
.event-block small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.event-block strong {
  font-size: 0.77rem;
  line-height: 1.1;
}
.event-block small {
  font-size: 0.66rem;
  font-weight: 850;
  opacity: 0.88;
}
.event-block .resize-handle {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 2px;
  height: 8px;
  border-radius: 999px;
  cursor: ns-resize;
}
.event-block:hover .resize-handle {
  background: rgba(20, 32, 51, 0.12);
}
.event-plan { background: var(--plan); color: var(--plan-ink); }
.event-candidate {
  background: var(--candidate);
  color: var(--candidate-ink);
  border-style: dashed;
}
.event-hold {
  background: var(--hold);
  color: var(--hold-ink);
  border-style: dashed;
}
.event-buffer { background: var(--buffer); color: var(--buffer-ink); }
.event-deadline { background: var(--deadline); color: var(--deadline-ink); }
.event-busy { background: var(--busy); color: var(--busy-ink); }
.event-window {
  background: var(--window);
  color: var(--window-ink);
  border-style: dashed;
}
.event-block.selected {
  outline: 3px solid rgba(249, 115, 22, 0.45);
  outline-offset: 2px;
}
body.is-painting .event-block { pointer-events: none; }

.status-line {
  margin: 12px 4px 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

@media (max-width: 780px) {
  .topbar {
    align-items: stretch;
    border-radius: 24px;
  }
  .top-actions {
    justify-content: flex-end;
  }
  .top-actions .quiet-button {
    min-height: 36px;
    padding: 0 10px;
  }
  .top-actions .main-button {
    min-height: 36px;
    padding: 0 12px;
  }
  .brand-copy small { display: none; }
  .preview-head,
  .tool-strip {
    align-items: stretch;
    flex-direction: column;
  }
  .summary-chips { justify-content: flex-start; }
  .soft-main { width: 100%; }
  .object-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .object-title-field,
  .object-note-field,
  .memo-field { grid-column: span 2; }
}

@media (max-width: 520px) {
  .app,
  .topbar { width: min(100% - 16px, 1180px); }
  .topbar {
    position: static;
    flex-wrap: wrap;
  }
  .top-actions {
    width: 100%;
  }
  .top-actions > * {
    flex: 1 1 88px;
  }
  .setup-card { padding: 12px; }
  .scope-grid,
  .secondary-grid,
  .object-form {
    grid-template-columns: 1fr;
  }
  .object-title-field,
  .object-note-field,
  .memo-field { grid-column: span 1; }
  .preview-head { padding: 14px; }
  .tool-strip { padding: 10px 14px; }
  .paint-button { flex: 1 1 70px; justify-content: center; }
  .object-panel { margin: 0 12px 12px; }
}

@media print {
  body { background: #fff; }
  .topbar,
  .setup-card,
  .tool-strip,
  .object-panel,
  .status-line { display: none !important; }
  .app { width: 100%; margin: 0; }
  .calendar-card { border: 0; box-shadow: none; }
  .calendar-scroller { max-height: none; overflow: visible; }
}
