:root {
  color-scheme: dark;
  --bg: #120d09;
  --card: rgba(29, 22, 16, 0.82);
  --line: rgba(255, 228, 185, 0.1);
  --line-strong: rgba(255, 228, 185, 0.2);
  --text: #f1e7d8;
  --body: #e2d7c5;
  --muted: #b2a38b;
  --kaya: #e2b265;
  --accent: #a083d6;
  --accent-deep: #5d4392;
  font-family: 'Inter', 'Noto Sans Thai', 'Noto Sans JP', 'Noto Sans KR', 'Noto Sans SC', 'Leelawadee UI', 'Segoe UI', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; font-size: 15px; line-height: 1.8; }
/* warm glow and a faint go-board grid behind everything */
body::before, body::after { content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none; }
body::before {
  background:
    radial-gradient(900px 520px at 8% -8%, rgba(160, 131, 214, 0.2), transparent 62%),
    radial-gradient(820px 480px at 100% 0%, rgba(226, 178, 101, 0.16), transparent 58%),
    var(--bg);
}
body::after {
  background-image: linear-gradient(rgba(226, 178, 101, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(226, 178, 101, 0.05) 1px, transparent 1px);
  background-size: 38px 38px;
  -webkit-mask-image: radial-gradient(ellipse at top, #000, transparent 72%);
  mask-image: radial-gradient(ellipse at top, #000, transparent 72%);
}
a { color: var(--kaya); text-decoration-color: rgba(226, 178, 101, 0.4); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--kaya); outline-offset: 3px; }

/* ---- top bar ---- */
.legal-top {
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 13, 9, 0.74);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
}
.legal-bar { display: flex; align-items: center; gap: 16px; width: min(1120px, 100%); margin: auto; padding: 12px 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-size: 17px; font-weight: 700; letter-spacing: 0.02em; text-decoration: none; }
.logo { width: 38px; height: 38px; border-radius: 10px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.legal-tabs { display: inline-flex; gap: 4px; margin: 0 auto; padding: 4px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); }
.legal-tabs a { padding: 6px 16px; border-radius: 999px; color: var(--muted); font-size: 14px; font-weight: 500; line-height: 1.6; white-space: nowrap; text-decoration: none; transition: color 0.15s, background 0.15s; }
.legal-tabs a:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.legal-tabs a[aria-current='page'] { color: #20160c; font-weight: 600; background: linear-gradient(135deg, #f2cd8c, var(--kaya)); box-shadow: 0 4px 14px rgba(226, 178, 101, 0.25); }

/* ---- language menu (flags: a native <select> cannot show pictures, and Windows draws no flag emoji) ---- */
.lang-picker { position: relative; flex: none; }
.lang-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
}
.lang-button:hover { background: rgba(255, 255, 255, 0.08); }
.lang-button::after { content: ''; width: 6px; height: 6px; margin: -4px 2px 0; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg); transition: transform 0.15s; }
.lang-button[aria-expanded='true']::after { margin-top: 3px; transform: rotate(-135deg); }
.lang-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  min-width: 176px;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: rgba(29, 22, 16, 0.97);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: menu-in 0.12s ease-out;
}
.lang-menu li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; font-size: 14px; line-height: 1.4; white-space: nowrap; cursor: pointer; outline: none; }
.lang-menu li:hover, .lang-menu li:focus { background: rgba(255, 255, 255, 0.07); }
.lang-menu li[aria-selected='true'] { color: var(--kaya); font-weight: 600; }
.lang-menu li[aria-selected='true']::after { content: '✓'; margin-left: auto; }
.flag { display: inline-block; flex: none; width: 21px; height: 14px; border-radius: 3px; background: #5b5348 center / cover no-repeat; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3); }
.flag[data-flag='th'] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Crect width='30' height='20' fill='%23a51931'/%3E%3Crect y='3.33' width='30' height='13.34' fill='%23f4f5f8'/%3E%3Crect y='6.67' width='30' height='6.66' fill='%232d2a4a'/%3E%3C/svg%3E"); }
.flag[data-flag='gb'] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'%3E%3Crect width='60' height='40' fill='%23012169'/%3E%3Cpath d='M0 0l60 40M60 0L0 40' stroke='%23fff' stroke-width='8'/%3E%3Cpath d='M0 0l60 40M60 0L0 40' stroke='%23c8102e' stroke-width='3'/%3E%3Cpath d='M30 0v40M0 20h60' stroke='%23fff' stroke-width='13'/%3E%3Cpath d='M30 0v40M0 20h60' stroke='%23c8102e' stroke-width='7'/%3E%3C/svg%3E"); }
.flag[data-flag='jp'] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Crect width='30' height='20' fill='%23fff'/%3E%3Ccircle cx='15' cy='10' r='6' fill='%23bc002d'/%3E%3C/svg%3E"); }
.flag[data-flag='cn'] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Crect width='30' height='20' fill='%23de2910'/%3E%3Cpolygon fill='%23ffde00' points='5.5,2 6.32,4.37 8.83,4.42 6.83,5.93 7.56,8.33 5.5,6.9 3.44,8.33 4.17,5.93 2.17,4.42 4.68,4.37'/%3E%3Cg fill='%23ffde00'%3E%3Ccircle cx='10.5' cy='2' r='0.8'/%3E%3Ccircle cx='12' cy='4' r='0.8'/%3E%3Ccircle cx='12' cy='6.6' r='0.8'/%3E%3Ccircle cx='10.5' cy='8.6' r='0.8'/%3E%3C/g%3E%3C/svg%3E"); }
.flag[data-flag='kr'] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 20'%3E%3Crect width='30' height='20' fill='%23fff'/%3E%3Ccircle cx='15' cy='10' r='5' fill='%230047a0'/%3E%3Cpath d='M10 10a5 5 0 0 1 10 0a2.5 2.5 0 0 1-5 0a2.5 2.5 0 0 0-5 0z' fill='%23cd2e3a'/%3E%3Cg stroke='%23000' stroke-width='1.1'%3E%3Cpath d='M4.2 6.2l3-3.2M5.2 7.1l3-3.2M6.2 8l3-3.2M20.8 3l3 3.2M21.8 4l1 1.1M23.5 5.9l1 1.1M22.8 4l3 3.2M4.2 13.8l3 3.2M5.2 12.9l1 1.1M6.9 14.8l1 1.1M6.2 12l3 3.2M20.8 17l3-3.2M21.8 16.1l3-3.2M22.8 17.9l3-3.2'/%3E%3C/g%3E%3C/svg%3E"); }

/* ---- contents + document ---- */
.legal-main { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 32px; align-items: start; width: min(1120px, 100%); margin: auto; padding: 40px 24px 56px; }
.legal-main > :not(.legal-toc) { grid-column: 2; }
.legal-toc { position: sticky; top: 88px; max-height: calc(100vh - 110px); overflow: auto; padding: 18px 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); }
.legal-toc summary { padding: 0 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; list-style: none; cursor: pointer; }
.legal-toc summary::-webkit-details-marker { display: none; }
.legal-toc summary::after { content: ''; float: right; width: 6px; height: 6px; margin: 5px 4px 0 0; border-right: 1.6px solid; border-bottom: 1.6px solid; transform: rotate(45deg); transition: transform 0.15s; }
.legal-toc[open] summary::after { margin-top: 8px; transform: rotate(-135deg); }
.legal-toc ol { display: grid; gap: 2px; margin: 12px 0 0; padding: 0; list-style: none; }
.legal-toc a { display: block; padding: 6px 10px; border-left: 2px solid transparent; border-radius: 0 8px 8px 0; color: var(--muted); font-size: 13.5px; line-height: 1.45; text-decoration: none; transition: color 0.15s, background 0.15s; }
.legal-toc a:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.legal-toc a.active { color: var(--kaya); border-left-color: var(--kaya); background: rgba(226, 178, 101, 0.08); }
.legal-card { min-height: 320px; padding: 44px 52px; border-radius: 24px; border: 1px solid var(--line); background: var(--card); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); }
.legal-card[aria-busy='true']::before { /* loading */
  content: '';
  display: block;
  height: 240px;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03)) 0 0 / 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
article h1 {
  margin: 0 0 6px;
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 800;
  line-height: 1.25;
  background: linear-gradient(120deg, #fff4df, var(--kaya) 60%, #c9a6ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
article h1 + p { display: inline-block; margin: 8px 0 18px; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--muted); font-size: 13px; }
article h2 { position: relative; margin: 36px 0 12px; padding-top: 26px; border-top: 1px solid var(--line); color: #f3dcb4; font-size: 19px; line-height: 1.45; scroll-margin-top: 92px; }
article h2::before { content: ''; position: absolute; top: -1px; left: 0; width: 48px; height: 2px; background: linear-gradient(90deg, var(--kaya), var(--accent)); }
p { margin: 12px 0; color: var(--body); overflow-wrap: anywhere; }
strong { color: #fff3e0; }
article ul, article ol { margin: 10px 0; padding: 0; list-style: none; }
article li { position: relative; margin: 8px 0; color: var(--body); overflow-wrap: anywhere; }
article ul li { padding-left: 24px; }
article ul li::before { /* a white stone */
  content: '';
  position: absolute;
  top: 0.66em;
  left: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #d6cdbf 60%, #8d8576);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
article ol { counter-reset: item; }
article ol li { padding-left: 32px; counter-increment: item; }
article ol li::before { /* a numbered black stone */
  content: counter(item);
  position: absolute;
  top: 0.3em;
  left: 0;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5a5a5a, #111 70%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  color: #f5ecdd;
  font-size: 11px;
  font-weight: 700;
  line-height: 21px;
  text-align: center;
}
.legal-error { color: #ffadad; }

/* ---- footer ---- */
.legal-foot { display: flex; justify-content: center; padding: 0 20px 48px; }
.back-login { display: inline-flex; align-items: center; gap: 8px; padding: 10px 22px; border-radius: 999px; background: linear-gradient(160deg, var(--accent), var(--accent-deep)); box-shadow: 0 8px 24px rgba(93, 67, 146, 0.4); color: #fff; font-weight: 600; text-decoration: none; transition: transform 0.15s; }
.back-login::before { content: '←'; }
.back-login:hover { transform: translateY(-1px); }
.to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: rgba(29, 22, 16, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
.to-top::before { content: ''; width: 10px; height: 10px; border-top: 2px solid; border-left: 2px solid; transform: translateY(3px) rotate(45deg); }
.to-top.shown { opacity: 1; pointer-events: auto; transform: none; }

@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 960px) {
  .legal-main { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 20px 16px 40px; }
  .legal-main > :not(.legal-toc) { grid-column: 1; }
  .legal-toc { position: static; max-height: none; padding: 14px; }
  .legal-card { padding: 30px 24px; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .legal-bar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .lang-picker { margin-left: auto; }
  .legal-tabs { order: 3; width: 100%; margin: 0; }
  .legal-tabs a { flex: 1; padding: 6px 8px; font-size: 13px; text-align: center; }
  .legal-card { padding: 24px 18px; border-radius: 18px; }
  article h2 { font-size: 17px; }
  .to-top { right: 14px; bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
