:root {
  --bg1: #fff6fb;
  --bg2: #ffe8f2;
  --bg3: #ffd7ea;
  --card: #ffffffe6;
  --text: #4b2a3d;
  --accent: #ff7fb6;
  --btn: #ff79b1;
  --btn-strong: #ff4f98;
  --btn-alt: #f5a8c9;
  --btn-alt-strong: #ee86b8;
  --board: #fff9fd;
  --line: #f4d4e5;
  --hairline: #ffffff;
  --soft-shadow: #a04f7640;
  --glass-bg: #ffffff9e;
  --glass-bg-strong: #fffffff0;
  --glass-stroke: #ffffffd6;
  --glass-shadow: #6e2c4e2b;
  --radius-lg: 22px;
  --radius-md: 16px;
  --blur: 16px;
}

@font-face {
  font-family: "PinyinUI";
  src: url("./fonts/pinyin-ui.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0020-007E, U+00C0-00FF, U+0100-017F, U+0251, U+02C7, U+0300, U+0301, U+0304, U+030C;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  background:
    radial-gradient(circle at 12% 8%, #ffffff 0%, transparent 38%),
    radial-gradient(circle at 88% 0%, #ffffffbf 0%, transparent 32%),
    radial-gradient(circle at 88% 88%, #ffffff8c 0%, transparent 28%),
    linear-gradient(165deg, var(--bg1) 0%, var(--bg2) 52%, var(--bg3) 100%);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  width: 100%;
  max-width: 1400px;
  display: grid;
  gap: 10px;
  grid-template-rows: auto 1fr auto;
  min-height: 100%;
  padding: 8px;
}

.panel {
  background:
    linear-gradient(160deg, #fffffffa 0%, var(--glass-bg) 58%, #ffdff08a 100%);
  border: 1px solid var(--glass-stroke);
  border-radius: var(--radius-lg);
  box-shadow:
    0 14px 32px var(--glass-shadow),
    inset 0 1px 0 #ffffff;
  backdrop-filter: blur(var(--blur)) saturate(1.16);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.16);
  padding: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 5vw, 40px);
  text-align: center;
}

.tri-stack,
.tri-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.pinyin-text {
  font-family: "PinyinUI", "Noto Sans", "Segoe UI", sans-serif;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "clig" 0;
  line-height: 1.1;
  letter-spacing: 0.01em;
}

.hanzi-text {
  line-height: 1.1;
}

.en-text {
  line-height: 1.1;
  letter-spacing: 0.04em;
  font-size: 0.8em;
  opacity: 0.9;
}

.stats {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: clamp(16px, 3vw, 20px);
}

.top-panel {
  padding: 4px 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0 10px;
}

.top-title {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: auto auto;
  align-content: center;
  gap: 0;
}

.top-panel .stats {
  grid-column: 2;
  grid-row: 1 / span 2;
  margin: 0;
  justify-content: flex-end;
  gap: 10px;
}

.top-panel .pinyin-text {
  font-size: clamp(10px, 1.4vw, 12px);
  opacity: 0.95;
}

.top-panel .hanzi-text {
  font-size: clamp(14px, 2vw, 18px);
  font-weight: 800;
}

.top-panel .en-text {
  display: none;
}

.top-panel .stat-item {
  flex-direction: row;
  gap: 6px;
}

.top-panel .stat-item .pinyin-text,
.top-panel .stat-item .en-text {
  display: none;
}

.top-panel .stat-item .hanzi-text {
  font-size: clamp(10px, 1.4vw, 12px);
  opacity: 0.92;
}

.top-panel .stat-item strong {
  font-size: clamp(14px, 2vw, 18px);
}

.stat-item {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.stat-item strong {
  margin-top: 2px;
}

.game-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
  min-height: 0;
  position: relative;
}

#game,
#next {
  background: var(--board);
  border-radius: var(--radius-md);
  border: 1px solid #ffffffd6;
  display: block;
  width: 100%;
  height: auto;
  box-shadow: inset 0 1px 0 #ffffff, 0 10px 24px #6e2c4e14;
}

.next-wrap {
  width: clamp(90px, 24vw, 140px);
  text-align: center;
  font-size: clamp(14px, 2.8vw, 18px);
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  max-width: 280px;
  justify-self: end;
  align-self: start;
  padding: 6px;
  background: linear-gradient(160deg, #fffffffa 0%, #ffffffd1 60%, #ffe0ee9a 100%);
  border: 1px solid var(--glass-stroke);
  box-shadow: 0 14px 28px #6e2c4e1f, inset 0 1px 0 #ffffff;
  backdrop-filter: blur(calc(var(--blur) - 2px)) saturate(1.12);
  -webkit-backdrop-filter: blur(calc(var(--blur) - 2px)) saturate(1.12);
}

.op-controls {
  display: none;
}

.thumb-zone {
  position: relative;
  display: none;
  min-height: 0;
  padding: 8px;
  width: min(240px, 19vw);
  height: min(240px, 19vw);
}

.op-btn {
  position: absolute;
  width: min(78px, 6.3vw);
  height: min(78px, 6.3vw);
  min-height: 62px;
  font-size: clamp(18px, 2.4vw, 24px);
  border-radius: 14px;
  background: linear-gradient(170deg, #ffc6df 0%, #ff7fb6 46%, #ff4f98 100%);
  box-shadow:
    0 16px 30px #ff6aa44a,
    inset 0 1px 0 #ffeaf3,
    inset 0 -1px 0 #ff4f9850;
  padding: 0;
  transform: rotate(45deg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.op-icon {
  transform: rotate(-45deg);
  font-size: 1.25em;
  line-height: 1;
  text-shadow: 0 1px 0 #ffffff42;
}

.action-rotate {
  left: 50%;
  top: 0;
  transform: translateX(-50%) rotate(45deg);
}

.action-down {
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) rotate(45deg);
}

.action-left {
  left: 0;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
}

.action-right {
  right: 0;
  top: 50%;
  transform: translateY(-50%) rotate(45deg);
}

.fn-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-width: 100%;
  justify-self: end;
  align-self: start;
}

.fn-controls .btn {
  min-height: 44px;
  font-size: clamp(12px, 2.2vw, 15px);
  border-radius: 10px;
  background:
    linear-gradient(180deg, #ffe8f2 0%, #f5bedc 55%, #ef93c2 100%);
  box-shadow:
    0 6px 14px #d57fa85e,
    inset 0 1px 0 #fff4fa;
  padding: 6px 4px;
}

.btn {
  border: 0;
  border-radius: 12px;
  min-height: 56px;
  font-size: clamp(14px, 2.8vw, 18px);
  font-weight: 700;
  color: #fff;
  background:
    linear-gradient(180deg, #ffd0e6 0%, #ff8fbe 58%, var(--btn) 100%);
  box-shadow:
    0 12px 24px #ff76ad3d,
    inset 0 1px 0 #ffe8f4;
}

.btn .pinyin-text {
  font-size: 0.54em;
}

.btn .hanzi-text {
  font-size: 0.72em;
}

.btn .en-text {
  font-size: 0.5em;
}

.btn:active {
  transform: scale(0.97) translateY(1px);
  filter: saturate(1.12) brightness(0.98);
}

@media (prefers-reduced-motion: no-preference) {
  .panel {
    animation: floatIn 360ms cubic-bezier(.2,.9,.2,1) both;
  }

  .thumb-zone {
    animation: floatIn 420ms 40ms cubic-bezier(.2,.9,.2,1) both;
  }
}

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

.btn-alt {
  background:
    linear-gradient(180deg, #ffe7f2 0%, #f8c0dc 60%, var(--btn-alt) 100%);
  box-shadow:
    0 5px 12px #dd8bb069,
    inset 0 1px 0 #fff7fb;
}

.btn:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 1px;
}

body.kid-mode h1 {
  font-size: clamp(30px, 6vw, 48px);
}

body.kid-mode .stats {
  font-size: clamp(18px, 3.4vw, 24px);
}

body.kid-mode .btn {
  min-height: 64px;
  font-size: clamp(16px, 3.3vw, 22px);
}

body.kid-mode .fn-controls .btn {
  min-height: 48px;
  font-size: clamp(13px, 2.3vw, 16px);
}

body.kid-mode .op-btn {
  width: min(84px, 7vw);
  height: min(84px, 7vw);
  min-height: 68px;
  font-size: clamp(20px, 2.8vw, 26px);
}

body.kid-mode .btn .pinyin-text {
  font-size: 0.58em;
}

@media (orientation: landscape) {
  .app {
    grid-template-columns: minmax(170px, 20vw) minmax(0, 1fr) minmax(170px, 20vw);
    grid-template-rows: auto minmax(0, 1fr);
    height: 100%;
    padding: 8px;
  }

  .top-panel {
    grid-column: 1 / 4;
    gap: 0 6px;
    padding: 3px 8px;
  }

  .top-panel .stats {
    font-size: clamp(12px, 1.4vw, 15px);
    gap: 8px;
  }

  .game-wrap {
    grid-column: 2;
    grid-row: 2;
    height: 100%;
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 8px;
  }

  #game {
    width: auto;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  .next-wrap {
    display: block;
    width: clamp(68px, 8vw, 92px);
    align-self: start;
    font-size: clamp(12px, 1.4vw, 14px);
  }

  #next {
    width: 100%;
    max-width: 92px;
    margin: 0 auto;
  }

  .controls {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    align-self: start;
    width: min(220px, 18vw);
    background: #ffffffd6;
  }

  .thumb-zone {
    display: grid;
    background:
      linear-gradient(160deg, #ffffffe8 0%, #ffffffb5 55%, #ffd8eb80 100%);
    border: 1px solid #ffffffd9;
    border-radius: 22px;
    box-shadow: 0 12px 24px #a85d833a, inset 0 1px 0 #ffffff;
    backdrop-filter: blur(12px) saturate(1.1);
    -webkit-backdrop-filter: blur(12px) saturate(1.1);
  }

  .left-zone {
    grid-column: 1;
    grid-row: 2;
    align-self: end;
    justify-self: stretch;
    padding: 8px 10px 18px max(8px, env(safe-area-inset-left));
  }

  .right-zone {
    grid-column: 3;
    grid-row: 2;
    align-self: end;
    justify-self: stretch;
    padding: 8px max(8px, env(safe-area-inset-right)) 18px 10px;
  }

  .fn-controls {
    align-content: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: minmax(42px, auto);
    max-width: 100%;
    justify-self: end;
  }

  .thumb-zone {
    justify-self: center;
  }
}

@media (orientation: portrait) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px;
    height: 100%;
    padding: 6px 6px calc(158px + env(safe-area-inset-bottom)) 6px;
  }

  .top-panel {
    gap: 0 6px;
    padding: 3px 7px;
  }

  .top-title .pinyin-text {
    font-size: clamp(9px, 2.4vw, 11px);
  }

  .top-title .hanzi-text {
    font-size: clamp(13px, 4vw, 16px);
  }

  .top-panel .stats {
    font-size: clamp(11px, 2.8vw, 14px);
    gap: 6px;
  }

  .controls {
    position: fixed;
    top: calc(6px + env(safe-area-inset-top));
    right: calc(6px + env(safe-area-inset-right));
    z-index: 19;
    max-width: min(240px, 54vw);
    padding: 6px;
    background: linear-gradient(160deg, #fffffffa 0%, #ffffffd6 60%, #ffe0ee9a 100%);
  }

  .fn-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .fn-controls .btn {
    min-height: 36px;
    font-size: clamp(11px, 2.7vw, 13px);
    border-radius: 9px;
  }

  .controls .en-text {
    display: none;
  }

  .controls .pinyin-text {
    font-size: 0.5em;
    opacity: 0.86;
  }

  .controls .hanzi-text {
    font-size: 0.78em;
  }

  .game-wrap {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 6px;
    align-items: stretch;
  }

  #game {
    width: auto;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
  }

  .next-wrap {
    position: absolute;
    top: 10px;
    right: 10px;
    width: clamp(64px, 18vw, 96px);
    font-size: clamp(10px, 2.4vw, 12px);
    opacity: 0.96;
    pointer-events: none;
  }

  #next {
    max-width: 96px;
  }

  .thumb-zone {
    display: block;
    position: fixed;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: min(144px, 39vw);
    height: min(144px, 39vw);
    z-index: 16;
    background:
      linear-gradient(160deg, #ffffffe8 0%, #ffffffb8 55%, #ffd8eb82 100%);
    border: 1px solid #ffffffd9;
    border-radius: 18px;
    box-shadow: 0 10px 20px #a85d833a, inset 0 1px 0 #ffffff;
    backdrop-filter: blur(12px) saturate(1.1);
    -webkit-backdrop-filter: blur(12px) saturate(1.1);
  }

  .left-zone {
    left: max(6px, env(safe-area-inset-left));
    padding: 7px;
  }

  .right-zone {
    display: block;
    right: max(6px, env(safe-area-inset-right));
    padding: 7px;
  }

  .op-btn {
    width: min(52px, 13.8vw);
    height: min(52px, 13.8vw);
    min-height: 46px;
  }

  .op-icon {
    font-size: 1.04em;
  }
}

@media (max-width: 520px) {
  .app {
    padding: 8px;
  }

  .controls {
    max-width: 100%;
    justify-self: stretch;
  }

  .fn-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-wrap {
    grid-template-columns: 1fr;
  }

  .next-wrap {
    width: 100%;
  }

  #next {
    max-width: 130px;
    margin: 0 auto;
  }
}
