:root {
  color-scheme: light;
  --ink: #17211e;
  --muted: #687873;
  --surface: #f8f4ec;
  --panel: #fffdf7;
  --line: #ddd4c4;
  --green: #0f6a50;
  --green-dark: #173f35;
  --cloth: #15745a;
  --amber: #d99b2b;
  --coral: #cf6959;
  --blue: #397caa;
  --shadow: 0 18px 38px rgba(31, 41, 37, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: #0f2d27;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, rgba(217, 155, 43, 0.18), transparent 28rem),
    linear-gradient(180deg, #183d34 0%, #f0e7d8 18%, #f6efe3 100%);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 2px 16px;
  color: #fffdf7;
}

.eyebrow {
  margin: 0 0 4px;
  color: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  opacity: 0.72;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 12vw, 3.6rem);
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.daily-card {
  display: grid;
  min-width: 74px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 253, 247, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.12);
  text-align: center;
  backdrop-filter: blur(14px);
}

.daily-card span {
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1;
}

.daily-card small {
  margin-top: 4px;
  color: rgba(255, 253, 247, 0.74);
}

main {
  display: grid;
  gap: 12px;
}

.table-section,
.controls-section,
.tab-panel,
.tab-nav {
  border: 1px solid rgba(68, 53, 31, 0.1);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.86);
  box-shadow: var(--shadow);
}

.table-section,
.controls-section,
.tab-panel {
  padding: 12px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}

.section-title-row.compact {
  margin-bottom: 12px;
}

.icon-button,
.ghost-button,
.primary-button,
.secondary-button,
.preset,
.tab-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  color: #fff;
  background: var(--green-dark);
  font-size: 1.25rem;
  font-weight: 900;
}

.ghost-button {
  min-height: 38px;
  padding: 0 14px;
  color: var(--green-dark);
  background: #efe7d8;
  font-weight: 800;
}

.ghost-button.wide {
  width: 100%;
  margin-top: 12px;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 8px solid #734a2e;
  border-radius: 8px;
  background: #734a2e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  touch-action: none;
}

#tableCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1.74 / 1;
  border-radius: 4px;
  background: var(--cloth);
  touch-action: none;
}

.canvas-hint {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 7px 9px;
  border-radius: 8px;
  color: #fffdf7;
  background: rgba(15, 45, 39, 0.72);
  font-size: 0.75rem;
  font-weight: 700;
  pointer-events: none;
}

.readout-grid,
.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.readout-grid > div,
.stats-strip > div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf8f0;
}

.readout-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.readout-grid strong,
.stats-strip strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  line-height: 1.15;
}

.control-board {
  display: grid;
  grid-template-columns: minmax(116px, 0.9fr) minmax(0, 1.3fr);
  gap: 12px;
  align-items: center;
}

.tip-area {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.tip-area p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
  text-align: center;
}

.tip-pad {
  position: relative;
  width: min(34vw, 148px);
  min-width: 116px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, #fff 0 9%, transparent 10%),
    radial-gradient(circle at 42% 36%, #ffffff 0%, #ede7dc 48%, #cfc5b7 100%);
  box-shadow:
    inset -10px -12px 22px rgba(71, 63, 51, 0.18),
    0 10px 22px rgba(31, 41, 37, 0.15);
  touch-action: none;
}

.tip-ring,
.safe-zone,
.tip-axis,
.tip-knob {
  position: absolute;
  pointer-events: none;
}

.tip-ring {
  inset: 16%;
  border: 1px solid rgba(23, 33, 30, 0.14);
  border-radius: 50%;
}

.safe-zone {
  inset: 30%;
  border: 1px dashed rgba(15, 106, 80, 0.4);
  border-radius: 50%;
}

.tip-axis.horizontal {
  top: 50%;
  left: 16%;
  width: 68%;
  height: 1px;
  background: rgba(23, 33, 30, 0.16);
}

.tip-axis.vertical {
  top: 16%;
  left: 50%;
  width: 1px;
  height: 68%;
  background: rgba(23, 33, 30, 0.16);
}

.tip-knob {
  width: 22px;
  height: 22px;
  border: 3px solid #fffdf7;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 6px 14px rgba(31, 41, 37, 0.24);
  transform: translate(-50%, -50%);
}

.slider-stack {
  display: grid;
  gap: 10px;
}

.range-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

.range-row strong {
  color: var(--ink);
  text-align: right;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.preset-row,
.tab-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 12px;
}

.preset,
.tab-button {
  min-height: 38px;
  padding: 0 6px;
  color: var(--muted);
  background: #efe7d8;
  font-size: 0.82rem;
  font-weight: 900;
}

.preset.active,
.tab-button.active {
  color: #fffdf7;
  background: var(--green-dark);
}

.tab-nav {
  position: sticky;
  top: 8px;
  z-index: 4;
  padding: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.course-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(96px, 0.55fr);
  gap: 12px;
  align-items: stretch;
  margin-bottom: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.course-copy p:not(.eyebrow) {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.progress-meter {
  display: grid;
  align-content: center;
  gap: 9px;
  min-width: 0;
}

.progress-meter strong {
  display: block;
  font-size: 1.35rem;
  line-height: 1;
}

.progress-meter span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.progress-track {
  overflow: hidden;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(23, 33, 30, 0.14);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--amber), var(--coral));
  transition: width 220ms ease;
}

.drill-card {
  padding: 14px;
  border-radius: 8px;
  color: #fffdf7;
  background:
    linear-gradient(135deg, rgba(21, 116, 90, 0.94), rgba(23, 63, 53, 0.98)),
    var(--green-dark);
}

.drill-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.drill-topline span {
  align-self: start;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.18);
  font-size: 0.73rem;
  font-weight: 900;
}

.drill-card h2 {
  margin: 4px 0 8px;
  font-size: 1.24rem;
}

.drill-card p:not(.eyebrow) {
  margin-bottom: 14px;
  color: rgba(255, 253, 247, 0.8);
  line-height: 1.55;
}

.lesson-progress {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.lesson-progress .progress-track {
  background: rgba(255, 253, 247, 0.22);
}

.lesson-progress strong {
  font-size: 0.78rem;
  white-space: nowrap;
}

.drill-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  font-weight: 900;
}

.primary-button {
  color: var(--green-dark);
  background: #fffdf7;
}

.secondary-button {
  color: #fffdf7;
  background: rgba(255, 253, 247, 0.18);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.drill-list,
.lesson-list,
.practice-history {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.mini-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.mini-card.locked {
  opacity: 0.58;
}

.mini-card.active-lesson {
  border-color: rgba(15, 106, 80, 0.42);
  box-shadow: inset 0 0 0 1px rgba(15, 106, 80, 0.2);
}

.lesson-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.lesson-index {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: #fffdf7;
  background: var(--green-dark);
  font-size: 0.82rem;
  font-weight: 900;
}

.locked .lesson-index {
  color: var(--muted);
  background: #e4dacb;
}

.lesson-state {
  color: var(--green-dark);
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
}

.mini-card button {
  justify-self: start;
}

.mini-card h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.mini-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.48;
  font-size: 0.9rem;
}

.mini-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-meta span {
  padding: 4px 7px;
  border-radius: 999px;
  color: var(--green-dark);
  background: #e7efe4;
  font-size: 0.72rem;
  font-weight: 900;
}

.lesson-card {
  position: relative;
  overflow: hidden;
}

.lesson-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent, var(--green));
}

.empty-state {
  padding: 18px 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

@media (max-width: 374px) {
  .app-shell {
    padding-inline: 10px;
  }

  .control-board {
    grid-template-columns: 1fr;
  }

  .tip-pad {
    width: min(42vw, 136px);
  }

  .readout-grid,
  .stats-strip {
    grid-template-columns: 1fr;
  }

  .course-overview,
  .drill-actions {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 760px) {
  .app-shell {
    width: min(100%, 960px);
  }

  main {
    grid-template-columns: 1.15fr 0.85fr;
    align-items: start;
  }

  .table-section,
  .tab-nav,
  .tab-panel {
    grid-column: 1;
  }

  .controls-section {
    position: sticky;
    top: 14px;
    grid-column: 2;
    grid-row: 1 / span 4;
  }
}
