:root {
  --ink: #10211e;
  --muted: #6a8079;
  --line: rgba(16, 33, 30, 0.1);
  --panel: #f4f8f6;
  --panel-edge: rgba(255, 255, 255, 0.55);
  --danger: #b33a2e;
  --ok: #1f6f6a;
  --accent: #c9782a;
  --font-display: "Bricolage Grotesque", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --arrow-w: min(520px, calc(100% - 2rem));
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #0d1a18;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(31, 111, 106, 0.38), transparent 55%),
    radial-gradient(ellipse 70% 45% at 80% 100%, rgba(201, 120, 42, 0.16), transparent 50%),
    linear-gradient(180deg, #0b1614 0%, #132522 50%, #0f1c1a 100%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.85rem + var(--safe-top)) 1rem 0.85rem;
  background: rgba(10, 24, 22, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #eef5f1;
  min-width: 0;
}
.brand-mark {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  clip-path: polygon(0 18%, 62% 18%, 62% 0, 100% 50%, 62% 100%, 62% 82%, 0 82%);
  background: linear-gradient(135deg, #1f6f6a, #c9782a);
}
.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 4vw, 1.3rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 0.1rem 0 0;
  font-size: 0.78rem;
  color: #9db5ae;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.6rem 1.05rem;
  font: 600 0.9rem var(--font-body);
  cursor: pointer;
  transition: transform .16s ease, opacity .16s ease, background .16s ease;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, #c9782a, #e09a4d);
  color: #1a1208;
}
.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(179, 58, 46, 0.35);
}
.btn.small {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: rgba(16, 33, 30, 0.06);
  border-color: var(--line);
  color: var(--ink);
}
.btn.tiny {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 8px;
  background: rgba(16, 33, 30, 0.06);
  border: 1px solid var(--line);
  color: var(--ink);
}
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: rgba(16, 33, 30, 0.06);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}

.stage {
  position: relative;
  z-index: 2;
  height: calc(100dvh - 68px - var(--safe-top));
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding: 1.25rem 0 calc(2rem + var(--safe-bottom));
}

.hint {
  text-align: center;
  color: #a8c0b8;
  font-size: 0.98rem;
  line-height: 1.5;
  padding: 3rem 1.5rem;
}
.hint[hidden] { display: none; }

.board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ---- Centered arrow cards ---- */
.arrow {
  position: relative;
  width: var(--arrow-w);
  min-height: 112px;
  padding: 1.05rem 3.4rem 1.05rem 3.1rem;
  color: #fff;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, 0.28));
  transition: transform .2s cubic-bezier(.2, .8, .2, 1), filter .2s ease, opacity .2s ease;
  animation: riseIn .35s cubic-bezier(.2, .8, .2, 1) both;
}
.arrow::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--arrow-color, #1f6f6a);
  clip-path: polygon(0 14%, 70% 14%, 70% 0, 100% 50%, 70% 100%, 70% 86%, 0 86%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.arrow-body {
  display: block;
  max-width: 78%;
}
.arrow-title {
  margin: 0 0 0.35rem;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 4.2vw, 1.28rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.arrow-notes {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  line-height: 1.35;
  opacity: 0.92;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.arrow-fees {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.22);
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
}
.arrow-fees.cleared { opacity: 0.85; }

/* Big touch drag grip — immediate drag, no long-press */
.drag-grip {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 48px;
  z-index: 3;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.16);
  border-radius: 0;
  clip-path: polygon(0 14%, 100% 14%, 100% 86%, 0 86%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: grab;
  touch-action: none;
  -webkit-touch-callout: none;
}
.drag-grip span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.85);
  pointer-events: none;
}
.drag-grip:active { cursor: grabbing; background: rgba(0, 0, 0, 0.28); }

.arrow.is-origin {
  opacity: 0;
  pointer-events: none;
}

.arrow-placeholder {
  width: var(--arrow-w);
  border-radius: 16px;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.06);
  box-sizing: border-box;
  transition: height .15s ease;
}

.arrow-ghost {
  position: fixed !important;
  left: 0;
  top: 0;
  z-index: 9999;
  margin: 0;
  pointer-events: none;
  animation: none !important;
  opacity: 0.96;
  filter: drop-shadow(0 22px 34px rgba(0, 0, 0, 0.45));
  transform: translate3d(0, 0, 0);
  will-change: transform;
  transition: none !important;
}
.arrow-ghost .arrow-move,
.arrow-ghost .drag-grip { display: none !important; }

body.is-dragging {
  cursor: grabbing !important;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
body.is-dragging * { cursor: grabbing !important; }
.stage.is-sorting {
  touch-action: none;
}

.arrow-move {
  position: absolute;
  right: 2.6rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  z-index: 2;
}
.arrow-move button {
  width: 28px;
  height: 24px;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  touch-action: manipulation;
}
.arrow-move button:disabled {
  opacity: 0.25;
  cursor: default;
}

@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Detail sheet ---- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
  background: rgba(6, 14, 13, 0.62);
  backdrop-filter: blur(8px);
  animation: fadeIn .2s ease;
}
.overlay[hidden] { display: none; }
@media (min-width: 720px) {
  .overlay { place-items: center; align-items: center; }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.detail {
  width: 100%;
  max-width: 720px;
  padding: 0;
}
.detail-sheet {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: min(92dvh, 900px);
  background: var(--panel);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  animation: sheetUp .28s cubic-bezier(.2, .8, .2, 1);
  border-top: 4px solid var(--detail-color, #1f6f6a);
}
@media (min-width: 720px) {
  .detail { padding: 1rem; }
  .detail-sheet {
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  }
}

.detail-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.25rem 1.25rem;
}
.detail-top h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}
.detail-scroll {
  overflow: auto;
  padding: 0.75rem 1.25rem 1rem;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}
.detail-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.25rem calc(1rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.5);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.95rem;
}
.field > span {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.field input[type="text"],
.field input[type="number"],
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  font: 500 1rem var(--font-body);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus,
.field textarea:focus {
  border-color: #1f6f6a;
  box-shadow: 0 0 0 3px rgba(31, 111, 106, 0.14);
}
#f-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
}

.money-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.money-grid .remaining-box { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .money-grid { grid-template-columns: 1fr 1fr 1.1fr; }
  .money-grid .remaining-box { grid-column: auto; }
}
.remaining-box {
  justify-content: center;
  background: linear-gradient(160deg, rgba(31, 111, 106, 0.1), rgba(201, 120, 42, 0.1));
  border-radius: 14px;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
}
.remaining-box strong {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
}

.color-row { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
#f-color {
  width: 44px;
  height: 44px;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
}
.swatches { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
  cursor: pointer;
}
.swatch.active { outline: 2px solid var(--ink); outline-offset: 2px; }

.subtasks-block { margin-top: 0.35rem; }
.subtasks-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.2rem;
}
.subtasks-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
}
.subtasks-hint {
  margin: 0 0 0.7rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.subtasks-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.subtask-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto;
  gap: 0.4rem;
  align-items: center;
  padding: 0.55rem 0.65rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.subtask-row.done input { text-decoration: line-through; opacity: 0.55; }
.subtask-row input[type="text"] {
  border: none;
  background: transparent;
  padding: 0.35rem 0.15rem;
  font: 500 0.95rem var(--font-body);
  width: 100%;
  outline: none;
}
.subtask-row .colon {
  font-weight: 700;
  color: var(--muted);
  font-family: var(--font-display);
}
.subtask-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--ok);
}

  @media (max-width: 560px) {
  .arrow {
    min-height: 104px;
    padding: 0.95rem 3.2rem 0.95rem 3rem;
  }
  .drag-grip { width: 46px; }
  .arrow::before {
    clip-path: polygon(0 16%, 68% 16%, 68% 0, 100% 50%, 68% 100%, 68% 84%, 0 84%);
  }
  .arrow-move { right: 2.2rem; }
  .subtask-row {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "check task del"
      ". staff staff";
  }
  .subtask-row input[type="checkbox"] { grid-area: check; }
  .subtask-row .task-input { grid-area: task; }
  .subtask-row .colon { display: none; }
  .subtask-row .staff-input {
    grid-area: staff;
    border-top: 1px dashed var(--line);
    padding-top: 0.4rem;
  }
  .subtask-row .btn.tiny { grid-area: del; }
}
