:root {
  --water: #08141a;
  --lagoon: #123038;
  --foam: #d7efe8;
  --sand: #f0d7a4;
  --coral: #e07a5f;
  --mute: #8aa8a3;
  --line: rgba(215, 239, 232, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 80% -10%, #1b4a4a 0%, transparent 55%),
    radial-gradient(900px 420px at -10% 110%, #16324a 0%, transparent 50%),
    var(--water);
  color: var(--foam);
  font-family: "Source Sans 3", sans-serif;
}

body {
  min-height: 100vh;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

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

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

.mark {
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 46% 54%;
  background: linear-gradient(160deg, #7ec8c8, #245e63 62%, #f0d7a4 100%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}

.brand p {
  margin: 0;
  color: var(--mute);
  font-size: 0.92rem;
}

.file-btn,
.mode-btn,
.text-btn,
.ghost-header-btn {
  cursor: pointer;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  background: var(--sand);
  color: #1b2a24;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  border: 0;
}

.file-btn input,
.import-btn input {
  display: none;
}

.island-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.island-select-wrap select {
  min-width: 160px;
  max-width: 220px;
}

.ghost-header-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

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

.modal {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  background: #10282e;
  color: var(--foam);
  width: min(420px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(4, 12, 16, 0.72);
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
}

.modal label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--mute);
  font-size: 0.92rem;
}

.modal input,
.modal select {
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-areas: "dock stage";
  gap: 18px;
}

.dock {
  grid-area: dock;
}

.stage {
  grid-area: stage;
}

.dock,
.stage {
  background: color-mix(in srgb, var(--lagoon) 88%, black);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.dock {
  padding: 16px 12px 12px;
  min-height: 540px;
  display: flex;
  flex-direction: column;
}

.dock-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 0 8px 10px;
  color: var(--mute);
  font-size: 0.86rem;
}

.dock-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.text-btn {
  background: none;
  border: 0;
  color: var(--sand);
  padding: 0;
  font: inherit;
}

.phrase-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}

.phrase-list li {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.phrase-list li span.index {
  color: var(--mute);
  min-width: 1.5rem;
  font-size: 0.8rem;
}

.phrase-list li.active {
  background: rgba(240, 215, 164, 0.12);
  color: var(--sand);
}

.hint {
  margin: 12px 8px 4px;
  color: var(--mute);
  font-size: 0.9rem;
}

.hint.hidden {
  display: none;
}

.stage {
  padding: 36px 28px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-height: 540px;
}

.progress {
  margin: 0;
  color: var(--mute);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.78rem;
}

.phrase-card {
  margin: 28px 0 24px;
  padding: 16px 20px 18px;
  width: min(100%, 620px);
  background: rgba(240, 215, 164, 0.08);
  border: 1px solid var(--line);
  border-radius: 18px;
  cursor: pointer;
}

.phrase-card:hover,
.phrase-card:focus-visible {
  border-color: rgba(240, 215, 164, 0.35);
  outline: none;
}

.phrase {
  margin: 0;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(2.2rem, 6vw, 4.4rem);
  line-height: 1.7;
  ruby-position: under;
}

.phrase ruby {
  ruby-align: center;
}

.phrase rt {
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.38em;
  font-weight: 600;
  color: var(--sand);
  letter-spacing: 0.02em;
}

.pinyin {
  margin: 14px 0 0;
  color: #ffe7b3;
  font-size: clamp(1.15rem, 2.6vw, 1.7rem);
  letter-spacing: 0.04em;
  line-height: 1.45;
}

.pinyin.missing {
  color: var(--coral);
}

.gloss {
  min-height: 1.4em;
  margin: 16px 0 0;
  color: var(--mute);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.phrase-card.revealed .gloss {
  color: var(--foam);
  font-size: 1.08rem;
  letter-spacing: 0.01em;
}

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

.transport button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--foam);
  font-size: 1.6rem;
  cursor: pointer;
}

.transport .play {
  width: 76px;
  height: 76px;
  background: var(--sand);
  color: #1b2a24;
  border: 0;
  font-size: 1.8rem;
}

.controls {
  width: min(460px, 100%);
  margin-top: 28px;
  display: grid;
  gap: 12px;
}

.controls label {
  display: grid;
  grid-template-columns: 64px 1fr 48px;
  align-items: center;
  gap: 10px;
  color: var(--mute);
  font-size: 0.9rem;
}

.voice-note {
  margin: 0;
  color: var(--mute);
  font-size: 0.9rem;
}

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

select {
  background: #0d1f24;
  color: var(--foam);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}

.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 24px;
}

.mode-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: #2a6d6a;
  color: white;
  font-weight: 600;
}

.mode-btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--foam);
}

.mode-btn.active {
  background: var(--coral);
}

.status {
  margin-top: 18px;
  color: var(--mute);
  min-height: 1.3em;
}

code {
  color: var(--sand);
}

@media (max-width: 800px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    min-height: 100dvh;
  }

  .app {
    height: 100dvh;
    padding: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .top {
    flex-shrink: 0;
    margin-bottom: 12px;
    align-items: flex-start;
  }

  .island-select-wrap select {
    max-width: 140px;
    min-width: 120px;
  }

  .layout {
    flex: 1;
    min-height: 0;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(150px, 30vh);
    grid-template-areas:
      "stage"
      "dock";
    gap: 10px;
  }

  .stage {
    min-height: 0;
    overflow: auto;
    padding: 16px 16px 12px;
  }

  .dock {
    min-height: 0;
    max-height: none;
  }

  .phrase-card {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: 8px 0 12px;
    background: #10282e;
  }
}
