/* PATHAI Junction Simulator: sandalwood theme */
:root {
  --sand-50: #fbf5e9;
  --sand-100: #f6ecd8;
  --sand-200: #eddcba;
  --sand-300: #dfc59a;
  --sand-400: #c9a672;
  --sand-600: #8f6a3d;
  --wood: #4a331f;
  --wood-2: #33251a;
  --bg: #f1e4cb;
  --panel: #fbf5e9;
  --panel2: #f3e6cc;
  --line: #dcc59b;
  --text: #3b2a1a;
  --muted: #86694a;
  --a: #b8452f;       /* controller A, fixed timer */
  --b: #1f7a6b;       /* controller B, PATHAI */
  --accent: #c8862b;  /* saffron */
  --danger: #b4321f;
  --radius: 16px;
  --shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 6px 18px -8px rgba(74,51,31,.35), 0 1px 3px rgba(74,51,31,.12);
  --ease: cubic-bezier(.22,.8,.24,1);
  font-family: "Segoe UI Variable", "Segoe UI", Inter, system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; color: var(--text); }
body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 520px at 12% -8%, rgba(255,246,222,.95), transparent 60%),
    radial-gradient(900px 600px at 105% 6%, rgba(232,196,140,.55), transparent 62%),
    linear-gradient(180deg, #f4e8d0 0%, #ecdbb8 100%);
  background-attachment: fixed;
}

/* ---------- header ---------- */
.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between;
  padding: 12px 24px; position: sticky; top: 0; z-index: 10;
  background: rgba(246,236,216,.78); backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid rgba(201,166,114,.55); box-shadow: 0 8px 24px -16px rgba(74,51,31,.5); }
.brand { display: flex; gap: 14px; align-items: center; }
.brand h1 { margin: 0; font-size: 21px; letter-spacing: .4px; font-weight: 800; color: var(--wood); }
.brand h1 span { color: var(--b); font-weight: 600; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.logo { width: 20px; height: 48px; background: linear-gradient(180deg, #4a331f, #2c1f13); border-radius: 7px; display: flex; flex-direction: column; justify-content: space-around; align-items: center; padding: 4px 0; box-shadow: 0 4px 10px -3px rgba(44,31,19,.6); }
.logo .l { width: 10px; height: 10px; border-radius: 50%; opacity: .28; }
.logo .r { background: #ef4444; } .logo .a { background: #f59e0b; } .logo .g { background: #22c55e; opacity: 1; box-shadow: 0 0 10px #22c55e; animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 5px #22c55e; } 50% { box-shadow: 0 0 14px 2px #4ade80; } }

/* ---------- tabs with a sliding indicator ---------- */
.tabs { position: relative; display: flex; gap: 2px; flex-wrap: wrap; padding: 4px; border-radius: 999px; background: rgba(223,197,154,.45); border: 1px solid rgba(201,166,114,.6); }
.tab-ind { position: absolute; top: 4px; bottom: 4px; left: 0; width: 0; border-radius: 999px; background: linear-gradient(180deg, #5a3f27, #3d2a1a); box-shadow: 0 4px 10px -3px rgba(61,42,26,.7);
  transition: transform .45s var(--ease), width .45s var(--ease); z-index: 0; }
.tab { position: relative; z-index: 1; background: transparent; border: 0; color: var(--muted); padding: 8px 16px; border-radius: 999px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; transition: color .3s var(--ease), transform .2s var(--ease); }
.tab:hover { color: var(--wood); transform: translateY(-1px); }
.tab.active { color: #fbf1dc; }

main { padding: 18px 24px 8px; max-width: 1640px; margin: 0 auto; }
.tabpane { display: none; }
.tabpane.active { display: block; animation: paneIn .55s var(--ease) both; }
@keyframes paneIn { from { opacity: 0; transform: translateY(14px) scale(.995); filter: blur(3px); } to { opacity: 1; transform: none; filter: none; } }
.tabpane.active .card { animation: cardIn .6s var(--ease) both; }
.tabpane.active .card:nth-child(2) { animation-delay: .06s; }
.tabpane.active .card:nth-child(3) { animation-delay: .12s; }
.tabpane.active .side .card:nth-child(1) { animation-delay: .08s; } .tabpane.active .side .card:nth-child(2) { animation-delay: .16s; } .tabpane.active .side .card:nth-child(3) { animation-delay: .24s; }
.tabpane.active .dash .card:nth-child(1) { animation-delay: .1s; } .tabpane.active .dash .card:nth-child(2) { animation-delay: .18s; } .tabpane.active .dash .card:nth-child(3) { animation-delay: .26s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ---------- control bar ---------- */
.bar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 16px; padding: 10px 14px; border-radius: var(--radius); background: rgba(251,245,233,.7); border: 1px solid var(--line); box-shadow: var(--shadow); }
.inline { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12.5px; font-weight: 600; }
select, input[type=number] { background: var(--sand-50); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font: inherit; font-size: 13px; transition: border-color .25s, box-shadow .25s, transform .2s var(--ease); }
select { cursor: pointer; }
select:hover, input[type=number]:hover { border-color: var(--sand-400); transform: translateY(-1px); }
select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200,134,43,.25); }
input[type=number] { width: 70px; }

/* ---------- buttons ---------- */
.btn { position: relative; overflow: hidden; isolation: isolate; background: linear-gradient(180deg, #fffaf0, #f1e1c2); color: var(--wood); border: 1px solid var(--sand-300); border-radius: 12px;
  padding: 8px 16px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; letter-spacing: .1px;
  box-shadow: 0 1px 0 rgba(255,255,255,.9) inset, 0 3px 8px -3px rgba(74,51,31,.35);
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), background .3s, border-color .3s, color .3s; }
.btn::before { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.55) 50%, transparent 70%); transform: translateX(-120%); transition: transform .7s var(--ease); }
.btn:hover { transform: translateY(-2px); border-color: var(--sand-400); box-shadow: 0 1px 0 rgba(255,255,255,.9) inset, 0 10px 18px -8px rgba(74,51,31,.5); }
.btn:hover::before { transform: translateX(120%); }
.btn:active { transform: translateY(0) scale(.96); box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 2px 4px -2px rgba(74,51,31,.5); transition-duration: .08s; }
.btn:focus-visible, .tab:focus-visible { outline: 3px solid rgba(200,134,43,.45); outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, #5d4129, #3b2a1a); color: #fbf1dc; border-color: #2d1f13; }
.btn.primary:hover { background: linear-gradient(180deg, #6b4b2f, #45311f); }
.btn.accent { background: linear-gradient(180deg, #e0a043, #c07f23); color: #2f1d06; border-color: #a6691a; margin-left: auto; }
.btn.accent:hover { background: linear-gradient(180deg, #e8ad55, #cb8a2c); }
.btn.danger { background: linear-gradient(180deg, #c9442d, #9e2b19); color: #fff3ec; border-color: #7e2010; }
.btn.danger:hover { background: linear-gradient(180deg, #d4513a, #a93220); }
.btn.danger:not(:disabled):not(:hover) { animation: pulseRing 2.8s ease-out infinite; }
@keyframes pulseRing { 0% { box-shadow: 0 0 0 0 rgba(180,50,31,.45); } 70%, 100% { box-shadow: 0 0 0 12px rgba(180,50,31,0); } }
.btn.danger:disabled { opacity: .55; cursor: default; transform: none; animation: none; }
.btn.wide { width: 100%; padding: 11px; }
.btn.ov.on { background: linear-gradient(180deg, #2f8f7d, #1f6c5e); color: #f2fffb; border-color: #175246; box-shadow: 0 0 0 3px rgba(31,122,107,.22), 0 6px 12px -6px rgba(23,82,70,.7); }
.ripple { position: absolute; border-radius: 50%; pointer-events: none; z-index: -1; background: rgba(255,255,255,.55); transform: scale(0); animation: ripple .65s var(--ease) forwards; }
.btn.primary .ripple, .btn.danger .ripple { background: rgba(255,255,255,.3); }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

.clock { display: flex; flex-direction: column; align-items: flex-end; font-variant-numeric: tabular-nums; }
.clock span { font-size: 22px; font-weight: 700; color: var(--wood); letter-spacing: .5px; }
.clock small { color: var(--muted); font-size: 11px; }

/* ---------- layout ---------- */
.simgrid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; }
.canvases { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; transition: all .4s var(--ease); }
.canvases.one { grid-template-columns: 1fr; max-width: none; }
.canvases canvas { width: 100%; height: auto; aspect-ratio: 600 / 720; background: #2b2016; border-radius: var(--radius); border: 1px solid #5a4530; display: block;
  box-shadow: 0 18px 34px -20px rgba(60,40,20,.75), 0 2px 6px rgba(60,40,20,.25); transition: box-shadow .4s var(--ease), transform .4s var(--ease); cursor: grab; touch-action: none; animation: cvIn .6s var(--ease) both; }
.canvases canvas:hover { box-shadow: 0 26px 44px -22px rgba(60,40,20,.85), 0 2px 6px rgba(60,40,20,.3); }
.canvases canvas.hide { display: none; }
.canvases canvas.grab { cursor: grabbing; }
@keyframes cvIn { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

.side { display: flex; flex-direction: column; gap: 14px; }
.card { background: linear-gradient(180deg, rgba(255,251,242,.96), rgba(249,240,222,.96)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); transition: transform .35s var(--ease), box-shadow .35s var(--ease), border-color .35s; }
.side .card:hover, .dash .card:hover { transform: translateY(-2px); border-color: var(--sand-400); box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 16px 28px -14px rgba(74,51,31,.45); }
.card h3 { margin: 0 0 12px; font-size: 14px; letter-spacing: .3px; font-weight: 700; color: var(--wood); display: flex; align-items: baseline; gap: 6px; }
.card h3::before { content: ""; width: 4px; height: 14px; border-radius: 3px; background: linear-gradient(180deg, var(--accent), #8f5a14); align-self: center; }
.card h3 small { color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 12px; margin: 9px 0 0; line-height: 1.45; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.row2 select { width: 100%; min-width: 0; }
.row2 label { min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.conf { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.conf div { font-size: 10.5px; color: var(--muted); }
.conf .meter { height: 6px; border-radius: 3px; background: var(--sand-200); overflow: hidden; margin-top: 4px; }
.conf .meter i { display: block; height: 100%; background: linear-gradient(90deg, #2f8f7d, #1f7a6b); transition: width .5s var(--ease); border-radius: 3px; }
.conf .meter i.low { background: linear-gradient(90deg, #d4513a, #b4321f); }

.override { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.override .btn { padding: 8px 4px; }
.override .release { grid-column: span 4; }

.slider { display: grid; grid-template-columns: 52px 1fr 48px; gap: 10px; align-items: center; font-size: 12px; margin: 8px 0; color: var(--muted); font-weight: 600; }
.slider input { width: 100%; accent-color: var(--accent); height: 4px; cursor: pointer; }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--wood); }

.dash { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 16px; margin-top: 16px; }
#metrics { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
#metrics th, #metrics td { padding: 7px 6px; border-bottom: 1px solid var(--sand-200); text-align: right; }
#metrics tbody tr { transition: background .25s; }
#metrics tbody tr:hover { background: rgba(223,197,154,.3); }
#metrics th:first-child, #metrics td:first-child { text-align: left; color: var(--muted); }
#metrics thead th { font-size: 12px; }
#metrics .ca { color: var(--a); } #metrics .cb { color: var(--b); }
#metrics .good { color: #1e7a45; font-weight: 700; } #metrics .bad { color: #b4321f; font-weight: 700; }
.chartcard canvas { width: 100%; display: block; border-radius: 10px; background: #2b2016; margin-bottom: 8px; }
.logcard ol { margin: 0; padding: 0; list-style: none; max-height: 330px; overflow: auto; font-size: 12px; font-family: Consolas, "Cascadia Mono", monospace; scrollbar-width: thin; scrollbar-color: var(--sand-400) transparent; }
.logcard li { padding: 5px 0; border-bottom: 1px dashed var(--sand-300); color: #5a4430; animation: logIn .4s var(--ease) both; }
@keyframes logIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.logcard li b { color: var(--muted); font-weight: 400; margin-right: 6px; }
.logcard li.warn { color: #9a6208; } .logcard li.alarm { color: #b4321f; } .logcard li.ok { color: #1e7a45; }

canvas.full { width: 100%; height: auto; display: block; border-radius: 10px; background: #2b2016; }
#resultTables table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 16px; font-variant-numeric: tabular-nums; }
#resultTables th, #resultTables td { border-bottom: 1px solid var(--sand-200); padding: 7px 8px; text-align: right; }
#resultTables th:first-child, #resultTables td:first-child { text-align: left; }
#resultTables caption { text-align: left; font-weight: 700; padding: 4px 0 8px; color: var(--wood); }
.prose { line-height: 1.6; font-size: 14px; max-width: 980px; }
.prose h2 { font-size: 18px; margin: 20px 0 6px; color: var(--wood); } .prose h2:first-child { margin-top: 0; }
.prose table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.prose td, .prose th { border: 1px solid var(--sand-300); padding: 6px 10px; }
.prose th { background: var(--sand-200); }
.prose code { background: var(--sand-200); padding: 1px 6px; border-radius: 5px; }
.foot { color: var(--muted); font-size: 12px; text-align: center; padding: 22px; }

::selection { background: rgba(200,134,43,.35); }
::-webkit-scrollbar { width: 10px; height: 10px; } ::-webkit-scrollbar-thumb { background: var(--sand-400); border-radius: 8px; border: 2px solid var(--bg); }

@media (max-width: 1150px) { .simgrid { grid-template-columns: 1fr; } .dash { grid-template-columns: 1fr; } }
@media (max-width: 700px) { main { padding: 12px 14px; } .canvases { grid-template-columns: 1fr; } .btn.accent { margin-left: 0; } .top { padding: 10px 14px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
