:root {
  --bg: #0b0d12;
  --panel: rgba(255, 255, 255, 0.06);
  --panel2: rgba(255, 255, 255, 0.08);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --muted2: rgba(255, 255, 255, 0.5);
  --stroke: rgba(255, 255, 255, 0.12);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius2: 12px;
  --focus-ring: 0 0 0 3px rgba(90, 160, 255, 0.5);
  --transition-fast: 0.15s ease;
  --transition-medium: 0.25s ease;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 800px at 20% 10%, rgba(255, 80, 80, 0.08), transparent 55%),
    radial-gradient(900px 600px at 80% 20%, rgba(90, 160, 255, 0.10), transparent 60%),
    radial-gradient(900px 900px at 60% 90%, rgba(120, 255, 210, 0.06), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-overflow-scrolling: touch;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.app {
  width: min(920px, 95vw);
  margin: 48px auto;
  padding: 24px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: linear-gradient(to bottom, rgba(255,255,255,0.05), rgba(255,255,255,0.03));
  box-shadow: var(--shadow);
}

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-weight: 720;
  letter-spacing: -0.02em;
  font-size: 26px;
  line-height: 1.2;
}

.sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.explainer {
  margin: 10px 0 0;
  color: var(--muted2);
  font-size: 13px;
  line-height: 1.45;
}

.composer {
  padding: 14px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 20px;
}

form {
  display: flex;
  gap: 10px;
}

input[type="text"] {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius2);
  border: 1px solid var(--stroke);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="text"]::placeholder { color: var(--muted2); }

input[type="text"]:focus {
  border-color: rgba(90, 160, 255, 0.5);
  background: rgba(0,0,0,0.35);
  box-shadow: var(--focus-ring);
}

button {
  padding: 11px 14px;
  border-radius: var(--radius2);
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.10);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:hover:not(:disabled) {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.22);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.ghost {
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--muted);
}

.ghost:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dot { opacity: 0.5; }

.mainGrid {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  margin-bottom: 20px;
}

.pieWrap {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: rgba(0,0,0,0.18);
  padding: 20px;
}

#pieChart {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.4));
}

.slice {
  transition: all 0.3s ease;
  transform-origin: center;
  cursor: pointer;
}

.slice path {
  will-change: filter, stroke-width;
  transition: filter 0.2s ease, stroke-width 0.2s ease, stroke 0.2s ease;
}

.slice:hover path {
  filter: brightness(1.15);
  stroke-width: 3;
}

.slice.selected path {
  filter: brightness(1.2);
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 4;
}

.empty {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  position: absolute;
  inset: 0;
}

.emptyIcon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty p {
  margin: 4px 0;
  line-height: 1.5;
}

.empty strong {
  color: var(--text);
  font-weight: 600;
}

.listSection {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sectionTitle {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.list::-webkit-scrollbar { width: 6px; }
.list::-webkit-scrollbar-track { background: transparent; }
.list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
}
.list::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

.listItem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius2);
  background: var(--panel);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.listItem:hover {
  background: var(--panel2);
  border-color: rgba(255,255,255,0.18);
}

.listItem.selected {
  background: rgba(90, 160, 255, 0.12);
  border-color: rgba(90, 160, 255, 0.4);
}

.listItem.dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

.listItem.dragOver {
  border-color: rgba(90, 160, 255, 0.6);
  background: rgba(90, 160, 255, 0.08);
}

.indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dragHandle {
  cursor: grab;
  color: var(--muted2);
  font-size: 14px;
  line-height: 1;
  user-select: none;
  padding: 2px;
  transition: color var(--transition-fast);
  flex-shrink: 0;
}

.dragHandle:hover { color: var(--muted); }
.listItem.dragging .dragHandle { cursor: grabbing; }

.itemContent {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.itemText {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.itemMeta {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
  flex-shrink: 0;
}

.itemActions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.arrowBtn, .deleteBtn {
  padding: 4px 8px;
  font-size: 14px;
  min-width: 28px;
  line-height: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
}

.arrowBtn:hover:not(:disabled) {
  background: rgba(255,255,255,0.12);
}

.deleteBtn:hover:not(:disabled) {
  background: rgba(255, 80, 80, 0.15);
  border-color: rgba(255, 80, 80, 0.3);
  color: #ff8080;
}

.controls {
  padding: 14px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: var(--panel);
  margin-top: 20px;
  animation: slideIn 0.2s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.controlsHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.controlsHeader h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.controlsPercent {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 14px;
  flex-shrink: 0;
  margin-left: 8px;
}

.controlButtons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--stroke);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.footerLeft {
  display: flex;
  align-items: center;
  gap: 12px;
}

.footerRight {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footerBtn {
  padding: 6px 10px;
  font-size: 13px;
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--muted);
}

.footerBtn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.modalOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modalOverlay.open { display: flex; }

.modalContent {
  background: linear-gradient(to bottom, rgba(20,22,28,0.98), rgba(15,17,22,0.98));
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  max-height: 80vh;
  overflow-y: auto;
}

.modalHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modalHeader h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.modalClose {
  background: transparent;
  border: 1px solid var(--stroke);
  padding: 6px 12px;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
}

.modalClose:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}

.modalBody {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.modalBody p { margin: 12px 0; }
.modalBody strong { color: var(--text); font-weight: 600; }
.modalBody a {
  color: rgba(90, 160, 255, 0.9);
  text-decoration: none;
  transition: color var(--transition-fast);
}
.modalBody a:hover { color: rgba(90, 160, 255, 1); text-decoration: underline; }

.modalBody ul {
  padding-left: 24px;
  margin: 12px 0;
}

.modalBody li {
  margin: 6px 0;
}

.floating {
  position: fixed;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 50px;
  background: rgba(20,22,28,0.92);
  border: 1px solid var(--stroke);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition-medium);
  z-index: 1000;
  backdrop-filter: blur(8px);
}

.floating:hover {
  background: rgba(25,27,33,0.95);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.floating img {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.sheety-float {
  bottom: 24px;
  right: 24px;
}

.kofi-float {
  bottom: 84px;
  right: 24px;
}

.kofi-icon {
  filter: brightness(1.1);
}

.label {
  font-weight: 500;
  white-space: nowrap;
}

@media (max-width: 800px) {
  .app {
    margin: 20px auto;
    padding: 16px;
    width: 100%;
  }

  h1 {
    font-size: 22px;
  }

  .sub {
    font-size: 13px;
  }

  .explainer {
    font-size: 12px;
  }

  .mainGrid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .pieWrap {
    order: -1; /* Show pie chart first on mobile */
  }

  .composer {
    padding: 12px;
  }

  form {
    flex-direction: column;
  }

  input[type="text"] {
    width: 100%;
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 14px;
  }

  button {
    width: 100%;
    padding: 14px;
    font-size: 15px;
  }

  .itemActions {
    gap: 6px;
  }

  .arrowBtn, .deleteBtn {
    padding: 8px 10px;
    font-size: 16px;
    min-width: 36px;
    touch-action: manipulation;
  }

  .controlButtons {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .controlBtn {
    padding: 14px;
    font-size: 15px;
  }

  .footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .footerLeft {
    order: 2;
    justify-content: center;
    text-align: center;
  }

  .footerRight {
    order: 1;
    flex-direction: column;
    gap: 8px;
  }

  .footerBtn {
    width: 100%;
    padding: 12px;
    font-size: 14px;
  }

  .hint {
    font-size: 11px;
  }

  .floating {
    padding: 8px 12px;
    font-size: 13px;
  }

  .floating img {
    width: 20px;
    height: 20px;
  }

  .sheety-float {
    bottom: 20px;
    right: 20px;
  }

  .kofi-float {
    bottom: 70px;
    right: 20px;
  }

  .listItem {
    padding: 12px;
    gap: 8px;
  }

  .dragHandle {
    font-size: 16px;
    padding: 4px;
  }

  .itemText {
    font-size: 15px;
  }

  .itemMeta {
    font-size: 14px;
  }

  .modalContent {
    padding: 20px;
    max-width: calc(100% - 32px);
  }

  .modalHeader h2 {
    font-size: 18px;
  }

  .modalBody {
    font-size: 13px;
  }

  #introModal .modalHeader h2 {
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  .app { 
    margin: 12px auto;
    padding: 12px;
  }
  
  h1 { 
    font-size: 20px; 
  }

  .sub {
    font-size: 12px;
  }

  .explainer {
    display: none; /* Hide detailed explainer on very small screens */
  }

  .floating .label { 
    display: none; 
  }
  
  .floating { 
    padding: 10px;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    justify-content: center;
  }

  .floating img {
    width: 24px;
    height: 24px;
  }

  .sheety-float {
    bottom: 16px;
    right: 16px;
  }

  .kofi-float {
    bottom: 70px;
    right: 16px;
  }

  .dragHandle {
    display: none; /* Hide drag handle on very small screens - use up/down arrows instead */
  }

  .itemActions {
    flex-wrap: nowrap;
  }

  .arrowBtn, .deleteBtn {
    padding: 10px 12px;
    font-size: 18px;
  }

  .list {
    max-height: 400px;
  }

  .controlsHeader h3 {
    font-size: 14px;
  }

  .controlButtons {
    gap: 6px;
  }

  .controlBtn {
    padding: 12px;
    font-size: 14px;
  }
}

/* ── Intro Modal Specific Styling ── */
#introModal {
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
}

#introModal .modalContent {
  max-width: 420px;
  text-align: center;
  background: linear-gradient(to bottom, rgba(21,24,33,0.98), rgba(15,17,22,0.98));
}

#introModal .modalHeader {
  border-bottom: none;
  padding-bottom: 0;
  justify-content: center;
}

#introModal .modalHeader h2 {
  font-size: 24px;
  font-weight: 700;
}

#introModal .modalBody {
  padding-top: 8px;
}

#introModal .modalBody p {
  line-height: 1.6;
  color: rgba(207, 211, 255, 0.9);
}

#introModal .modalBody .subtle {
  opacity: 0.65;
  font-size: 14px;
  margin-top: 16px;
}

#introModal button {
  margin-top: 20px;
  background: #6ae3b4;
  color: #0b0d11;
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

#introModal button:hover {
  background: #7ff0c4;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(106, 227, 180, 0.3);
}
