/* Theme variables are switched via data-theme on <html> */
:root{
  --bg:#0b0d10;
  --card:#11151b;
  --panel:#0f1319;
  --text:#e9eef6;
  --muted:#97a3b6;
  --border:#222a35;
  --op:#121a26;
  --eq:#1d2633;
  --accent:#2b6cff;

  --screen:#0a0d12;
  --screen2:#0b0d10;
  --graphbg:#07090c;
  --grid:#1a2330;
  --axis:#516177;
  --plot:#9ad0ff;
}

html[data-theme="ti84"]{
  --bg:#1a1b1f;
  --panel:#2a2d34;
  --card:#23262d;
  --text:#f2f5fb;
  --muted:#c0c8d6;
  --border:#3a3f4a;
  --op:#2c3240;
  --eq:#36425d;
  --accent:#6bb3ff;

  --screen:#1e232d;
  --screen2:#1b2029;
  --graphbg:#141821;
  --grid:#2a3240;
  --axis:#93a3bd;
  --plot:#d0e7ff;
}

html[data-theme="ti83"]{
  --bg:#101316;
  --panel:#1b2025;
  --card:#161b20;
  --text:#f0f4f2;
  --muted:#b5c1bb;
  --border:#2b333a;
  --op:#1d2530;
  --eq:#223240;
  --accent:#7ee0a5;

  --screen:#0f1416;
  --screen2:#101517;
  --graphbg:#0a0e10;
  --grid:#1c262d;
  --axis:#89a79c;
  --plot:#c9ffe4;
}

*{box-sizing:border-box}
body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
}

/* Make the page breathe on all screens */
.shell{
  max-width:1180px;
  margin:0 auto;
  padding: clamp(10px, 2vw, 18px);
}

/* Header: wrap-friendly */
.top{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:12px;
  margin-bottom:14px;
  flex-wrap:wrap;
}
.title{font-weight:800;font-size:18px}
.sub{color:var(--muted);font-size:13px;margin-top:2px}
.link{color:var(--muted);text-decoration:none}
.link:hover{color:var(--text)}

.toolbar{
  display:flex;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  justify-content:flex-end;
}
.pill{
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--card);
  color:var(--text);
  padding:8px 10px;
  cursor:pointer;
  font-size:12px;
  font-weight:700;
}
.pill.alt{background:transparent;color:var(--muted)}
.pill:hover{filter:brightness(1.07)}
.selectWrap{display:flex;align-items:center;gap:8px}
.selectWrap select{
  background:transparent;
  color:var(--text);
  border:0;
  outline:none;
  font-weight:800;
  cursor:pointer;
}

/* Main layout: responsive columns */
.calc{
  display:grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap:12px;
  align-items:start;
}
.leftPane{min-width:0}

/* Screen */
.screen{
  background:linear-gradient(180deg,var(--screen), var(--screen2));
  border:1px solid var(--border);
  border-radius:14px;
  padding:14px;
  margin-bottom:12px;
}
.line{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}
.small{color:var(--muted);font-size:12px;min-height:16px}
.expr{color:var(--muted);font-size:13px;min-height:18px;word-break:break-word}
.big{font-size:clamp(26px, 4.6vw, 34px);font-weight:800;min-height:40px;word-break:break-word}

/* Key grid: tighter on small devices */
.grid{
  display:grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(8px, 1.2vw, 10px);
}
.k{
  padding: clamp(10px, 2.0vw, 12px) clamp(8px, 1.6vw, 10px);
  border-radius:14px;
  border:1px solid var(--border);
  background:var(--card);
  color:var(--text);
  cursor:pointer;
  font-weight:800;
  min-height:44px; /* thumb-friendly */
}
.k:hover{filter:brightness(1.08)}
.k.op{background:var(--op)}
.k.alt{background:color-mix(in oklab, var(--card), transparent 20%); color:var(--muted)}
.k.eq{background:var(--eq)}
.k.wide{grid-column: span 2}

/* History panel: not insanely tall on mobile */
.history{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px;
  display:flex;
  flex-direction:column;
  min-height: 520px;
}
.histHead{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}
.mini{
  border-radius:10px;border:1px solid var(--border);
  background:var(--card);color:var(--text);
  padding:6px 10px;cursor:pointer;font-size:12px
}
.histBody{
  flex:1;
  overflow:auto;
  border-top:1px solid var(--border);
  padding-top:10px;
}
.item{padding:8px 0;border-bottom:1px dashed rgba(255,255,255,.10)}
.item .q{color:var(--muted);font-family:ui-monospace,monospace;font-size:12px}
.item .a{font-family:ui-monospace,monospace;font-size:14px;font-weight:900}
.hint{margin-top:10px;color:var(--muted);font-size:12px}

/* Graph */
.graph{
  border:1px solid var(--border);
  border-radius:14px;
  background:var(--panel);
  padding:12px;
  margin-bottom:12px;
}
.hidden{display:none}

.graphTop{
  display:flex;
  justify-content:space-between;
  gap:10px;
  align-items:center;
  flex-wrap:wrap;
  margin-bottom:10px;
}
.graphTitle{font-weight:900}
.graphControls{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.graphControls label{
  color:var(--muted);
  font-size:12px;
  display:flex;
  gap:6px;
  align-items:center
}
.graphControls input{
  width:76px;
  max-width: 30vw;
  border-radius:10px;
  border:1px solid var(--border);
  background:var(--card);
  color:var(--text);
  padding:6px 8px;
  outline:none
}

.graphFn{margin-bottom:10px}
.fnRow{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
  margin-top:8px
}
.fnInput{
  flex:1;
  min-width: 180px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--card);
  color:var(--text);
  padding:10px 12px;
  outline:none;
  font-family:ui-monospace,monospace;
}
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace}

/* Canvas: always fit container; keep ratio; prevent overflow */
canvas{
  width:100%;
  height:auto;
  display:block;
  border-radius:12px;
  background:var(--graphbg);
  border:1px solid var(--border);
  max-width: 100%;
}

/* --- Responsive breakpoints --- */
@media (max-width: 980px){
  .calc{grid-template-columns:1fr}
  .history{min-height:260px; max-height: 38vh;}
  .histBody{max-height: 28vh;}
}

@media (max-width: 520px){
  .toolbar{justify-content:flex-start}
  .history{max-height: 34vh;}
  .k{border-radius:12px}
  .screen{padding:12px}
}