:root {
  color-scheme: light;
  --bg: #f8f6f1;
  --surface: #ffffff;
  --surface-2: #f2eee6;
  --ink: #1f2725;
  --muted: #6c746f;
  --line: #ded7ca;
  --accent: #1f7a68;
  --accent-dark: #123f38;
  --accent-soft: #dceee9;
  --gold: #e7a72f;
  --danger: #b44747;
  --shadow: 0 10px 26px rgba(36, 31, 23, 0.07);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  max-width: 820px;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 100svh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 20px 14px;
  background: var(--accent-dark);
  color: #fff;
  text-align: center;
}

.app-header h1,
.page-title h2,
.section-title h3 {
  margin: 0;
}

.app-header h1 {
  font-size: 25px;
  line-height: 1.18;
}

.eyebrow {
  margin: 0 0 5px;
  color: inherit;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  opacity: 0.65;
  text-transform: uppercase;
}

.header-meta {
  margin: 7px 0 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
}

.icon-button,
.play-button,
.primary-button,
.ghost-button,
.small-button,
.collection-form button,
.import-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  font-weight: 800;
}

.icon-button {
  width: 44px;
  flex: 0 0 44px;
  color: #fff;
  background: #289681;
  font-size: 28px;
  line-height: 1;
}

.current-meta,
.hint,
.page-title span,
.vocab-meaning {
  color: var(--muted);
  font-size: 13px;
}

.play-button {
  min-width: 116px;
  padding: 0 20px;
  color: #173a36;
  background: var(--gold);
}

.play-button.compact {
  min-width: 82px;
}

.tab-page {
  display: none;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 104px;
}

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

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

.page-title h2 {
  font-size: 25px;
  line-height: 1.15;
}

.composer,
.section-block,
.player-panel,
.account-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.translate-toolbar,
.toggle-row,
.transport,
.backup-actions,
.rename-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.translate-toolbar {
  display: grid;
  gap: 10px;
}

.translate-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.translate-button {
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 800;
}

.translate-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.toggle-row {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.hint {
  margin: 10px 0 14px;
}

.field-block {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  outline: 0;
}

input,
select {
  min-height: 44px;
  padding: 0 13px;
}

textarea {
  display: block;
  resize: vertical;
  min-height: 130px;
  padding: 13px;
  line-height: 1.55;
}

.primary-button {
  width: 100%;
  margin-top: 14px;
  color: #fff;
  background: var(--accent);
}

.ghost-button,
.import-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.import-button input {
  display: none;
}

.collection-form {
  display: grid;
  grid-template-columns: 1fr 74px;
  gap: 10px;
  margin-bottom: 12px;
}

.collection-form button {
  color: #fff;
  background: var(--accent);
}

.play-card {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent-dark);
}

.play-card #playbackStatus {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.play-actions {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 10px;
}

.play-actions .ghost-button {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
}

.collection-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.collection-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 62px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.collection-select {
  display: grid;
  gap: 6px;
  min-width: 0;
  flex: 1;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.collection-item.active {
  border-color: #f3c55b;
  background: #f9d477;
}

.collection-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 850;
}

.collection-count {
  color: inherit;
  font-size: 13px;
  opacity: 0.72;
}

.section-block {
  margin-top: 14px;
}

.rename-group {
  align-items: stretch;
  margin-bottom: 14px;
}

.rename-group input {
  min-width: 0;
}

.rename-group button {
  flex: 0 0 72px;
  min-height: 44px;
}

.item-list {
  display: grid;
  gap: 10px;
}

.vocab-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.vocab-text {
  margin: 0;
  font-size: 17px;
  font-weight: 850;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.vocab-meaning {
  margin: 7px 0 0;
  color: var(--accent-dark);
  font-weight: 800;
  line-height: 1.45;
}

.item-actions {
  display: grid;
  gap: 8px;
  align-content: start;
}

.small-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.small-button.delete {
  color: var(--danger);
  background: #f4e0df;
}

.danger {
  color: var(--danger);
}

.empty-state {
  padding: 34px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  text-align: center;
}

.player-panel {
  display: grid;
  gap: 18px;
}

.transport {
  justify-content: center;
}

.transport .play-button {
  flex: 1;
  max-width: 220px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.settings-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.setting-static {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.setting-static strong {
  color: var(--ink);
  font-size: 14px;
}

.settings-grid input[type="range"] {
  accent-color: var(--accent);
}

.settings-grid .toggle-row {
  grid-template-columns: auto 1fr;
  align-content: center;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.account-panel {
  display: grid;
  gap: 12px;
}

.account-status {
  padding: 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent-dark);
  font-weight: 850;
  overflow-wrap: anywhere;
}

.account-fields {
  display: grid;
  gap: 10px;
}

.account-view {
  display: grid;
  gap: 12px;
}

.account-view[hidden] {
  display: none;
}

.account-primary {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 850;
}

.text-button {
  min-height: 36px;
  padding: 0;
  border: 0;
  color: var(--accent-dark);
  background: transparent;
  font-weight: 800;
  text-align: left;
}

.text-button:hover {
  color: var(--accent);
  text-decoration: underline;
}

.account-register-action {
  display: grid;
  gap: 4px;
}

.account-register-action .text-button {
  justify-self: end;
}

.account-signed-in {
  padding: 4px 0 0;
}

.logout-button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-dark);
  background: #fff;
  font-weight: 850;
}

.logout-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.account-dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(17, 42, 38, 0.25);
}

.account-dialog[open] {
  display: grid;
  gap: 16px;
}

.account-dialog::backdrop {
  background: rgba(22, 36, 33, 0.42);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-header h3 {
  margin: 0;
  font-size: 20px;
}

.dialog-close {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 26px;
  line-height: 1;
  place-items: center;
}

.dialog-notice {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 750;
  line-height: 1.45;
}

.dialog-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.dialog-actions .ghost-button {
  padding: 0 18px;
}

.code-row {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 10px;
}

.password-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px;
  gap: 8px;
}

.password-row input {
  min-width: 0;
}

.password-toggle {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-dark);
  background: #fff;
  font-weight: 800;
}

.export-dialog textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  line-height: 1.55;
}

.full-width {
  width: 100%;
}

.settings-actions {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.settings-actions .hint {
  text-align: center;
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.bottom-nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  padding: 7px 10px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.bottom-nav button {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 850;
}

.bottom-nav button span {
  font-size: 20px;
  line-height: 1;
}

.bottom-nav button.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.admin-body {
  min-height: 100vh;
  overflow: auto;
  background: var(--bg);
}

.admin-shell {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding: 20px;
  border-radius: 8px;
  color: #fff;
  background: var(--accent-dark);
}

.admin-header p,
.admin-header h1 {
  margin: 0;
}

.admin-header p {
  color: rgba(255, 255, 255, 0.68);
  font-size: 13px;
  font-weight: 800;
}

.admin-header h1 {
  margin-top: 4px;
  font-size: 26px;
}

.admin-header a {
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.admin-login,
.admin-stats,
.admin-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.admin-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 12px;
  padding: 18px;
}

.admin-login button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 850;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
}

.admin-stats article {
  padding: 20px;
  background: #fff;
}

.admin-stats span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.admin-stats strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.admin-table-wrap {
  margin-top: 16px;
  overflow-x: auto;
}

.admin-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.admin-table-wrap th,
.admin-table-wrap td {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.admin-table-wrap th {
  color: var(--muted);
  font-size: 13px;
}

@media (min-width: 760px) {
  .app-shell {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .tab-page {
    padding-left: 26px;
    padding-right: 26px;
  }
}

@media (max-width: 430px) {
  .app-header {
    padding: 18px 16px 15px;
  }

  .app-header h1 {
    font-size: 23px;
  }

  .tab-page {
    padding: 18px 14px 94px;
  }

  .settings-grid,
  .collection-list {
    grid-template-columns: 1fr;
  }

  .vocab-item {
    grid-template-columns: 1fr;
  }

  .item-actions {
    grid-template-columns: 1fr 1fr;
  }
}
