:root {
  --bg: #F4F1E8;
  --card: #FFFDF7;
  --line: #E4E0D2;
  --text: #1F271B;
  --muted: #6E7766;
  --matcha: #557A3C;
  --matcha-deep: #3F5F2E;
  --matcha-soft: #E6EDD6;
  --star-off: #DAD6C8;
  --star-on: #E8B23A;
  --bad: #C8553D;
  --shadow: 0 1px 2px rgba(40, 52, 30, .05), 0 6px 20px rgba(40, 52, 30, .06);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111510; --card: #1A2017; --line: #2C3527; --text: #E9EEDF; --muted: #93A086;
    --matcha: #9CCB6E; --matcha-deep: #C5E39F; --matcha-soft: #243020; --star-off: #3A4434;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  min-height: 100dvh;
}
button, textarea { font: inherit; color: inherit; }

.page {
  max-width: 1400px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) clamp(12px, 2.5vw, 32px) max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: clamp(12px, 2vh, 20px);
  min-height: 100dvh;
}

/* ---------- Đầu trang ---------- */
.top { display: flex; align-items: center; gap: clamp(12px, 2vw, 24px); animation: rise .5s ease both; }
.logo { height: clamp(44px, 7vh, 64px); width: auto; flex: none; }
.titles h1 { margin: 0; font-size: clamp(18px, 2.4vw, 28px); font-weight: 700; letter-spacing: -.01em; color: var(--matcha-deep); }
.titles p { margin: 2px 0 0; color: var(--muted); font-size: clamp(13px, 1.3vw, 15px); }

/* ---------- 4 cột tầng ---------- */
.floors { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(10px, 1.4vw, 18px); flex: 1; }
.floor {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(12px, 1.4vw, 18px);
  display: flex; flex-direction: column; gap: 6px; position: relative;
  transition: border-color .3s, box-shadow .3s, transform .3s;
  animation: rise .5s ease both;
}
.floor:nth-child(2) { animation-delay: .05s; }
.floor:nth-child(3) { animation-delay: .1s; }
.floor:nth-child(4) { animation-delay: .15s; }
.floor.active { border-color: var(--matcha); box-shadow: 0 0 0 3px var(--matcha-soft), var(--shadow); }
.floor-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.floor-name { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-weight: 700; font-size: clamp(16px, 1.6vw, 20px); }
.floor-num {
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  background: var(--matcha-soft); color: var(--matcha-deep); font-size: 18px; font-weight: 700;
  transition: background .3s, color .3s;
}
.floor.active .floor-num { background: var(--matcha); color: #fff; }
.clear {
  position: absolute; top: 10px; right: 8px; border: 0; background: none; color: var(--muted); font-size: 13px; padding: 6px 8px; border-radius: 8px;
  cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.floor.active .clear { opacity: 1; pointer-events: auto; }
.clear:hover { background: var(--matcha-soft); }

.crit { padding: 10px 0 8px; border-top: 1px dashed var(--line); flex: 1; display: flex; flex-direction: column; justify-content: center; }
.crit:first-of-type { border-top: 0; }
.crit-name { font-size: clamp(13px, 1.15vw, 15px); font-weight: 500; line-height: 1.3; min-height: 2.6em; display: flex; align-items: center; gap: 6px; }
.stars { display: flex; gap: clamp(2px, .4vw, 6px); margin-top: 4px; }
.star {
  flex: 1; max-width: var(--star-max, 48px); aspect-ratio: 1; border: 0; background: none; padding: 2px; cursor: pointer;
  border-radius: 10px; transition: transform .15s ease;
}
.star svg { width: 100%; height: 100%; display: block; fill: var(--star-off); transition: fill .2s ease, transform .2s ease; }
.star.on svg { fill: var(--star-on); }
.stars.low .star.on svg { fill: var(--bad); }
.star:active { transform: scale(.88); }
.star.pop svg { animation: pop .35s var(--d, 0ms) ease; }
/* Rê chuột: xem trước số sao sẽ chọn */
.stars.hovering .star svg { fill: var(--star-off); }
.stars.hovering .star.hov svg { fill: var(--star-on); }
.crit-label { font-size: 12.5px; color: var(--muted); height: 18px; margin-top: 2px; transition: color .2s; }
.crit-label.set { color: var(--matcha-deep); font-weight: 600; }
.stars.low + .crit-label.set { color: var(--bad); }

/* ---------- Góp ý ---------- */
.note {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(12px, 1.4vw, 18px); display: flex; flex-direction: column; gap: 10px;
  animation: rise .5s .2s ease both;
}
.note-label { font-weight: 600; }
.note-label span { font-weight: 400; color: var(--muted); font-size: 13px; }
textarea {
  width: 100%; resize: vertical; min-height: 72px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); padding: 12px 14px; font-size: 16px; line-height: 1.45; outline: none;
  transition: border-color .2s, box-shadow .2s;
}
textarea:focus { border-color: var(--matcha); box-shadow: 0 0 0 3px var(--matcha-soft); }
.note-row { display: flex; flex-direction: column; gap: 10px; }
.actions { display: flex; flex-direction: row-reverse; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 14px; }
.send {
  border: 0; border-radius: 16px; padding: 14px 34px; font-size: 17px; font-weight: 600; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, #78A04F, #3F5F2E); box-shadow: 0 6px 18px rgba(63, 95, 46, .28);
  transition: transform .15s, opacity .25s, box-shadow .25s;
}
.send:active { transform: scale(.97); }
.send:disabled { opacity: .45; box-shadow: none; cursor: default; }
.send.busy { pointer-events: none; opacity: .7; }

/* ---------- Cảm ơn ---------- */
.thanks {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity .35s ease;
}
.thanks.show { opacity: 1; pointer-events: auto; }
.thanks-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 28px; box-shadow: var(--shadow);
  padding: 36px 32px 28px; text-align: center; max-width: 420px; width: 100%;
  transform: translateY(16px) scale(.97); transition: transform .45s cubic-bezier(.2, .9, .3, 1.2);
}
.thanks.show .thanks-card { transform: none; }
.thanks h2 { margin: 14px 0 6px; color: var(--matcha-deep); font-size: 24px; }
.thanks p { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }
.check { width: 84px; height: 84px; }
.check circle { fill: var(--matcha-soft); stroke: var(--matcha); stroke-width: 2.5; }
.check path { fill: none; stroke: var(--matcha-deep); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 40; stroke-dashoffset: 40; }
.thanks.show .check path { animation: draw .5s .25s ease forwards; }
.again { border: 1px solid var(--line); background: var(--bg); border-radius: 14px; padding: 11px 22px; font-weight: 600; cursor: pointer; }
.again span { color: var(--muted); font-weight: 400; }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 30; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pop { 40% { transform: scale(1.25) rotate(-6deg); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Tablet / màn ngang: vừa khít 1 màn hình, không cần cuộn ---------- */
@media (orientation: landscape) and (min-width: 901px) {
  .page { height: 100dvh; min-height: 520px; gap: clamp(8px, 1.8vh, 18px); padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .floors { min-height: 0; }
  .floor { min-height: 0; padding-top: clamp(10px, 1.8vh, 18px); padding-bottom: clamp(6px, 1.2vh, 14px); }
  .crit { padding: clamp(4px, 1vh, 10px) 0; min-height: 0; }
  .crit-name { min-height: 2.6em; font-size: clamp(13px, min(1.25vw, 2.3vh), 17px); }
  .star { --star-max: clamp(36px, 7.5vh, 64px); }
  .crit-label { font-size: clamp(12px, 1.9vh, 14px); }
  /* Góp ý nằm ngang: ô nhập bên trái, nút Gửi bên phải */
  .note { gap: 6px; padding-top: clamp(8px, 1.4vh, 16px); padding-bottom: clamp(8px, 1.4vh, 16px); }
  .note-row { flex-direction: row; align-items: stretch; }
  .note-row textarea { flex: 1; min-height: clamp(52px, 10vh, 96px); height: clamp(52px, 10vh, 96px); resize: none; }
  .actions { flex-direction: column; justify-content: center; flex-wrap: nowrap; gap: 6px; min-width: 200px; }
  .send { width: 100%; padding: clamp(12px, 2.2vh, 18px) 28px; font-size: clamp(16px, 2.4vh, 19px); }
  .hint { font-size: 13px; }
}
/* Tablet nhỏ (≈1024×600): thu gọn đầu trang */
@media (orientation: landscape) and (min-width: 901px) and (max-height: 640px) {
  .logo { height: 40px; }
  .titles h1 { font-size: 20px; }
  .titles p { font-size: 13px; }
  .floor-num { width: 30px; height: 30px; font-size: 15px; }
  .floor-head { margin-bottom: 0; }
  .note-label { font-size: 14px; }
}

/* ---------- Màn nhỏ: 2 cột ---------- */
@media (max-width: 900px) {
  .floors { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .logo { height: 40px; }
  .titles h1 { font-size: 17px; }
  .titles p { font-size: 12.5px; }
  .floor { padding: 12px 10px; }
  .clear { top: 6px; right: 4px; font-size: 12px; }
  .floor-num { width: 30px; height: 30px; font-size: 15px; border-radius: 10px; }
  .crit { padding: 8px 0 6px; }
  .crit-name { font-size: 12.5px; }
  .crit-label { font-size: 11.5px; }
  .send { flex: 1; }
}
