/* ============================================================
   GATE Virtual Scientific Calculator — Stylesheet
   Includes: 3D styling, 4 colour themes
   ============================================================ */

/* ── Reset & base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── CSS custom properties (default = Classic Blue theme) ── */
:root {
  /* Page background */
  --bg-page:         #9aaabb;

  /* Calculator body */
  --calc-bg:         #cfd4dc;
  --calc-border:     #7a8898;
  --calc-shadow:     rgba(0,0,0,0.55);

  /* Title bar */
  --bar-bg:          linear-gradient(to bottom, #5ba3f0, #3372c4);
  --bar-border-top:  #6eb8ff;
  --bar-border-bot:  #1a52a8;
  --bar-text:        #fff;
  --bar-text-shadow: 0 1px 2px rgba(0,0,0,0.4);

  /* Help / Theme titlebar buttons */
  --tbtn-bg:         linear-gradient(to bottom, #6ab4f8, #3a84e0);
  --tbtn-border:     #1f5cb0;
  --tbtn-hover:      linear-gradient(to bottom, #4a98e8, #2062c8);
  --tbtn-text:       #fff;

  /* Displays */
  --disp-bg:         #e8f4e8;
  --disp-border:     #8aaa8a;
  --disp-expr-color: #446644;
  --disp-result-color:#0a2a0a;
  --disp-inset:      inset 2px 2px 6px rgba(0,0,0,0.25),
                     inset -1px -1px 3px rgba(255,255,255,0.4);

  /* Button area background */
  --btnarea-bg:      linear-gradient(to bottom, #bfc6d0, #adb4be);

  /* Normal buttons */
  --btn-bg-top:      #dde2ea;
  --btn-bg-bot:      #b0b8c4;
  --btn-border-top:  #e8edf5;
  --btn-border-bot:  #7a8898;
  --btn-color:       #1a2a3a;
  --btn-shadow:      0 4px 0 #7a8898, 0 5px 6px rgba(0,0,0,0.35);
  --btn-shadow-active: 0 1px 0 #7a8898, 0 2px 3px rgba(0,0,0,0.3);
  --btn-hover-top:   #cdd4de;
  --btn-hover-bot:   #a0a8b4;

  /* Red buttons */
  --btn-red-top:     #f06060;
  --btn-red-bot:     #c02020;
  --btn-red-border:  #801010;
  --btn-red-shadow:  0 4px 0 #801010, 0 5px 6px rgba(0,0,0,0.35);

  /* Green buttons */
  --btn-grn-top:     #58d858;
  --btn-grn-bot:     #289030;
  --btn-grn-border:  #0e6018;
  --btn-grn-shadow:  0 4px 0 #0e6018, 0 5px 6px rgba(0,0,0,0.35);

  /* Angle cell text */
  --angle-color:     #1a2a3a;

  /* ── Scale factor (1 = default 700px wide).
     JS writes this via ResizeObserver whenever the calc is resized.
     All font-sizes and display heights are expressed as
     calc(base * var(--scale)) so everything grows proportionally. ── */
  --scale: 1;
}

/* ============================================================
   THEME — Dark Graphite
   ============================================================ */
body.theme-graphite {
  --bg-page:         #1a1a1a;
  --calc-bg:         #2c2c2c;
  --calc-border:     #111;
  --calc-shadow:     rgba(0,0,0,0.8);
  --bar-bg:          linear-gradient(to bottom, #444, #222);
  --bar-border-top:  #666;
  --bar-border-bot:  #000;
  --bar-text:        #e0e0e0;
  --tbtn-bg:         linear-gradient(to bottom, #555, #333);
  --tbtn-border:     #111;
  --tbtn-hover:      linear-gradient(to bottom, #666, #444);
  --tbtn-text:       #e0e0e0;
  --disp-bg:         #111;
  --disp-border:     #000;
  --disp-expr-color: #55cc55;
  --disp-result-color:#88ff88;
  --disp-inset:      inset 2px 2px 8px rgba(0,0,0,0.7),
                     inset -1px -1px 2px rgba(255,255,255,0.05);
  --btnarea-bg:      linear-gradient(to bottom, #252525, #1c1c1c);
  --btn-bg-top:      #3a3a3a;
  --btn-bg-bot:      #222;
  --btn-border-top:  #555;
  --btn-border-bot:  #111;
  --btn-color:       #d0d0d0;
  --btn-shadow:      0 4px 0 #111, 0 5px 6px rgba(0,0,0,0.6);
  --btn-shadow-active: 0 1px 0 #111, 0 2px 3px rgba(0,0,0,0.5);
  --btn-hover-top:   #4a4a4a;
  --btn-hover-bot:   #303030;
  --btn-red-top:     #cc3333;
  --btn-red-bot:     #881111;
  --btn-red-border:  #440000;
  --btn-red-shadow:  0 4px 0 #440000, 0 5px 6px rgba(0,0,0,0.6);
  --btn-grn-top:     #33aa33;
  --btn-grn-bot:     #116611;
  --btn-grn-border:  #004400;
  --btn-grn-shadow:  0 4px 0 #004400, 0 5px 6px rgba(0,0,0,0.6);
  --angle-color:     #aaa;
}

/* ============================================================
   THEME — Midnight Purple
   ============================================================ */
body.theme-purple {
  --bg-page:         #1a0a2e;
  --calc-bg:         #2d1b4e;
  --calc-border:     #130a24;
  --calc-shadow:     rgba(80,0,180,0.5);
  --bar-bg:          linear-gradient(to bottom, #7b3fce, #4a1a9a);
  --bar-border-top:  #a060f0;
  --bar-border-bot:  #2a0a60;
  --bar-text:        #f0e0ff;
  --tbtn-bg:         linear-gradient(to bottom, #8a50dd, #5a28aa);
  --tbtn-border:     #2a0a70;
  --tbtn-hover:      linear-gradient(to bottom, #6a38bd, #3e1a8a);
  --tbtn-text:       #f0e0ff;
  --disp-bg:         #0d0620;
  --disp-border:     #3a1860;
  --disp-expr-color: #bb88ff;
  --disp-result-color:#e8ccff;
  --disp-inset:      inset 2px 2px 8px rgba(60,0,120,0.7),
                     inset -1px -1px 3px rgba(200,150,255,0.1);
  --btnarea-bg:      linear-gradient(to bottom, #251540, #1a0d30);
  --btn-bg-top:      #3d2468;
  --btn-bg-bot:      #251448;
  --btn-border-top:  #6040a0;
  --btn-border-bot:  #120820;
  --btn-color:       #dcc8ff;
  --btn-shadow:      0 4px 0 #120820, 0 5px 6px rgba(50,0,100,0.6);
  --btn-shadow-active: 0 1px 0 #120820, 0 2px 3px rgba(50,0,100,0.5);
  --btn-hover-top:   #503288;
  --btn-hover-bot:   #321c58;
  --btn-red-top:     #e04080;
  --btn-red-bot:     #901050;
  --btn-red-border:  #500030;
  --btn-red-shadow:  0 4px 0 #500030, 0 5px 6px rgba(50,0,100,0.6);
  --btn-grn-top:     #6040d0;
  --btn-grn-bot:     #3a1898;
  --btn-grn-border:  #200870;
  --btn-grn-shadow:  0 4px 0 #200870, 0 5px 6px rgba(50,0,100,0.6);
  --angle-color:     #cc99ff;
}

/* ============================================================
   THEME — Solar Gold
   ============================================================ */
body.theme-gold {
  --bg-page:         #2a1800;
  --calc-bg:         #3d2200;
  --calc-border:     #1a0e00;
  --calc-shadow:     rgba(180,80,0,0.5);
  --bar-bg:          linear-gradient(to bottom, #d4820a, #8a4800);
  --bar-border-top:  #f0aa30;
  --bar-border-bot:  #4a2000;
  --bar-text:        #fff8e0;
  --tbtn-bg:         linear-gradient(to bottom, #e09020, #a05800);
  --tbtn-border:     #502800;
  --tbtn-hover:      linear-gradient(to bottom, #c07010, #804000);
  --tbtn-text:       #fff8e0;
  --disp-bg:         #1a0e00;
  --disp-border:     #5a3000;
  --disp-expr-color: #ffcc66;
  --disp-result-color:#ffe8a0;
  --disp-inset:      inset 2px 2px 8px rgba(80,30,0,0.8),
                     inset -1px -1px 3px rgba(255,200,80,0.1);
  --btnarea-bg:      linear-gradient(to bottom, #341800, #261000);
  --btn-bg-top:      #5a3200;
  --btn-bg-bot:      #3a1e00;
  --btn-border-top:  #8a5a10;
  --btn-border-bot:  #1a0a00;
  --btn-color:       #ffe0a0;
  --btn-shadow:      0 4px 0 #1a0a00, 0 5px 6px rgba(80,30,0,0.6);
  --btn-shadow-active: 0 1px 0 #1a0a00, 0 2px 3px rgba(80,30,0,0.5);
  --btn-hover-top:   #6e4010;
  --btn-hover-bot:   #4a2a00;
  --btn-red-top:     #e06000;
  --btn-red-bot:     #903000;
  --btn-red-border:  #501800;
  --btn-red-shadow:  0 4px 0 #501800, 0 5px 6px rgba(80,30,0,0.6);
  --btn-grn-top:     #d0a000;
  --btn-grn-bot:     #906000;
  --btn-grn-border:  #503000;
  --btn-grn-shadow:  0 4px 0 #503000, 0 5px 6px rgba(80,30,0,0.6);
  --angle-color:     #ffcc88;
}

/* ============================================================
   Page & 3D scene
   ============================================================ */
body {
  background: var(--bg-page);
  /* subtle radial spotlight behind the calc */
  background-image: radial-gradient(ellipse 70% 60% at 50% 45%,
                      rgba(255,255,255,0.08) 0%, transparent 70%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  user-select: none;
  transition: background 0.4s;
  perspective: 1200px;        /* enables 3-D child transforms */
}

/* ============================================================
   Calculator shell — 3D raised slab
   ============================================================ */
#calculator {
  width: 700px;
  background: var(--calc-bg);
  border-radius: 10px;

  /* multi-layer border mimics a bevelled edge */
  border-top:    2px solid var(--bar-border-top);
  border-left:   2px solid var(--bar-border-top);
  border-right:  2px solid var(--calc-border);
  border-bottom: 2px solid var(--calc-border);

  /* layered shadows: soft ambient + hard drop = "lifted" look */
  box-shadow:
    0  2px  0   rgba(255,255,255,0.18),   /* top highlight */
    0  8px 20px var(--calc-shadow),        /* main drop shadow */
    0 20px 50px rgba(0,0,0,0.3),           /* wide ambient */
    inset 0 1px 0 rgba(255,255,255,0.15);  /* inner top gleam */

  /* overflow visible — resize handles live outside this box */
  overflow: visible;
  transition: background 0.4s, border-color 0.4s, box-shadow 0.4s;

  /* flex column so every child (titlebar, display, btn-area) can
     participate in the available height when the user resizes      */
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Title bar  — shiny metallic bar
   ============================================================ */
#titlebar {
  background: var(--bar-bg);
  display: flex;
  align-items: center;
  padding: 6px 8px;
  gap: 6px;

  border-bottom: 1px solid var(--bar-border-bot);
  box-shadow:
    inset 0 1px 0 var(--bar-border-top),   /* top gleam */
    0 2px 4px rgba(0,0,0,0.3);             /* drop under bar */
  transition: background 0.4s;
}

#titlebar .title {
  color: var(--bar-text);
  font-size: 15px;
  font-weight: bold;
  flex: 1;
  text-shadow: var(--bar-text-shadow);
  letter-spacing: 0.3px;
}

/* Help & Theme buttons in the title bar */
#btn-help,
#btn-theme {
  background: var(--tbtn-bg);
  color: var(--tbtn-text);
  border: 1px solid var(--tbtn-border);
  border-radius: 4px;
  padding: 2px 12px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--tbtn-border), 0 3px 4px rgba(0,0,0,0.3);
  transition: background 0.15s, box-shadow 0.1s, transform 0.1s;
  text-shadow: 0 1px 1px rgba(0,0,0,0.3);
}
#btn-help:hover,
#btn-theme:hover {
  background: var(--tbtn-hover);
}
#btn-help:active,
#btn-theme:active {
  box-shadow: 0 1px 0 var(--tbtn-border);
  transform: translateY(1px);
}

/* Theme button icon is slightly larger */
#btn-theme { font-size: calc(15px * var(--scale)); padding: 1px 10px; }

/* Minimise / Close chrome buttons */
.win-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 3px;
  width: 22px;
  height: 20px;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bar-text);
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
  transition: background 0.1s;
}
.win-btn:hover { background: rgba(255,255,255,0.28); }

#btn-close {
  background: linear-gradient(to bottom, #f04040, #c01010);
  border-color: #800000;
  color: #fff;
}
#btn-close:hover { background: linear-gradient(to bottom, #e02020, #a00000); }

/* ============================================================
   Display area  — fixed-height recessed screen panel.
   Heights are expressed with --scale so they grow with the
   calculator when resized, but always stay compact relative
   to the button grid (which fills all remaining space).
   ============================================================ */
#display-area {
  padding: 8px 10px 6px 10px;
  background: linear-gradient(to bottom,
    rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.04) 100%);
  border-bottom: 1px solid rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  gap: 5px;
  /* never grow: the display panel keeps its natural (content) height */
  flex: 0 0 auto;
  overflow: hidden;
}

/* Expression (top) — input echo */
#expr-display {
  width: 100%;
  background: var(--disp-bg);
  border: 1px solid var(--disp-border);
  border-radius: 4px;
  text-align: right;
  padding: 3px 10px;
  font-size: calc(14px * var(--scale));
  line-height: 1.4;
  /* fixed height so it doesn't blow up: 1 line of text + padding */
  height: calc(28px * var(--scale));
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: var(--disp-inset);
  transition: background 0.4s, color 0.4s, box-shadow 0.4s, font-size 0.1s, height 0.1s;
  font-family: 'Courier New', Courier, monospace;
  color: var(--disp-expr-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* Result (bottom) — large answer */
#result-display {
  width: 100%;
  background: var(--disp-bg);
  border: 1px solid var(--disp-border);
  border-radius: 4px;
  text-align: right;
  padding: 4px 10px;
  font-size: calc(26px * var(--scale));
  font-weight: bold;
  line-height: 1.3;
  /* fixed height: ~1.5× font size for breathing room */
  height: calc(44px * var(--scale));
  overflow: hidden;
  box-shadow: var(--disp-inset);
  transition: background 0.4s, color 0.4s, box-shadow 0.4s, font-size 0.1s, height 0.1s;
  font-family: 'Courier New', Courier, monospace;
  color: var(--disp-result-color);
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
#result-display.error { color: #ff4444; }

/* ============================================================
   Button area panel
   ============================================================ */
#btn-area {
  padding: 8px 10px 12px 10px;
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  /* 1fr rows — each row takes an equal share of whatever height
     the calculator has, so vertical resize works naturally       */
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  background: var(--btnarea-bg);
  border-top: 1px solid rgba(255,255,255,0.08);
  transition: background 0.4s;
  /* grow to fill all vertical space the flex-column parent offers */
  flex: 1 1 auto;
  min-height: 0;   /* required: lets a flex child shrink below content size */
  overflow: hidden; /* clip content, not resize handles (those are on #calculator) */
}

/* ============================================================
   Buttons — 3D raised pill style
   ============================================================ */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  /* bevelled border: lighter top-left, darker bottom-right */
  border-top:    1px solid var(--btn-border-top);
  border-left:   1px solid var(--btn-border-top);
  border-right:  1px solid var(--btn-border-bot);
  border-bottom: 1px solid var(--btn-border-bot);

  background: linear-gradient(to bottom, var(--btn-bg-top), var(--btn-bg-bot));
  color: var(--btn-color);
  font-family: Arial, Helvetica, sans-serif;
  /* font scales with the calculator size */
  font-size: calc(16px * var(--scale));
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  padding: 0 2px;

  /* thick bottom shadow = raised 3D look */
  box-shadow: var(--btn-shadow);

  transition: background 0.08s, box-shadow 0.08s, transform 0.08s, color 0.4s,
              border-color 0.4s, font-size 0.1s;
  text-shadow: 0 1px 1px rgba(255,255,255,0.3);
}

.btn:hover {
  background: linear-gradient(to bottom, var(--btn-hover-top), var(--btn-hover-bot));
}

/* Press: button sinks down — shadow collapses, element moves down */
.btn:active {
  box-shadow: var(--btn-shadow-active);
  transform: translateY(3px);
}

/* Superscript / subscript text inside buttons */
.btn sup,
.btn sub { font-size: calc(9px * var(--scale)); line-height: 0; }

/* ── Red variant (backspace, C) ── */
.btn-red {
  background: linear-gradient(to bottom, var(--btn-red-top), var(--btn-red-bot));
  color: #fff;
  border-top:    1px solid #ff9090;
  border-left:   1px solid #ff9090;
  border-right:  1px solid var(--btn-red-border);
  border-bottom: 1px solid var(--btn-red-border);
  box-shadow: var(--btn-red-shadow);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.btn-red:hover {
  background: linear-gradient(to bottom, #d84848, #a81818);
  filter: brightness(1.1);
}
.btn-red:active {
  box-shadow: 0 1px 0 var(--btn-red-border), 0 2px 3px rgba(0,0,0,0.4);
  transform: translateY(3px);
}

/* ── Green variant (=) ── */
.btn-green {
  background: linear-gradient(to bottom, var(--btn-grn-top), var(--btn-grn-bot));
  color: #fff;
  border-top:    1px solid #aaffaa;
  border-left:   1px solid #aaffaa;
  border-right:  1px solid var(--btn-grn-border);
  border-bottom: 1px solid var(--btn-grn-border);
  box-shadow: var(--btn-grn-shadow);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  font-size: calc(16px * var(--scale));
}
.btn-green:hover {
  filter: brightness(1.1);
}
.btn-green:active {
  box-shadow: 0 1px 0 var(--btn-grn-border), 0 2px 3px rgba(0,0,0,0.4);
  transform: translateY(3px);
}

/* ============================================================
   Deg / Rad angle-mode control  (grid cols 2–6, row 1)
   ============================================================ */
#angle-cell {
  grid-column: 2 / 7;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: calc(13px * var(--scale));
  font-weight: 600;
  color: var(--angle-color);
  padding-left: 6px;
  transition: color 0.4s, font-size 0.1s;
}
#angle-cell input[type="radio"] {
  accent-color: #4a90d9;
  cursor: pointer;
  margin: 0;
}
#angle-cell label { cursor: pointer; }

/* ============================================================
   Grid placement — every button's exact cell
   (unchanged from original layout)
   ============================================================ */

/* ROW 1 */
#r1-mod    { grid-column: 1;    grid-row: 1; }
#r1-MC     { grid-column: 7;    grid-row: 1; }
#r1-MR     { grid-column: 8;    grid-row: 1; }
#r1-MS     { grid-column: 9;    grid-row: 1; }
#r1-Mplus  { grid-column: 10;   grid-row: 1; }
#r1-Mminus { grid-column: 11;   grid-row: 1; }

/* ROW 2 */
#r2-sinh { grid-column: 1;   grid-row: 2; }
#r2-cosh { grid-column: 2;   grid-row: 2; }
#r2-tanh { grid-column: 3;   grid-row: 2; }
#r2-Exp  { grid-column: 4;   grid-row: 2; }
#r2-lp   { grid-column: 5;   grid-row: 2; }
#r2-rp   { grid-column: 6;   grid-row: 2; }
#r2-back { grid-column: 7/9; grid-row: 2; }
#r2-C    { grid-column: 9;   grid-row: 2; }
#r2-neg  { grid-column: 10;  grid-row: 2; }
#r2-sqrt { grid-column: 11;  grid-row: 2; }

/* ROW 3 */
#r3-asinh { grid-column: 1;  grid-row: 3; }
#r3-acosh { grid-column: 2;  grid-row: 3; }
#r3-atanh { grid-column: 3;  grid-row: 3; }
#r3-log2  { grid-column: 4;  grid-row: 3; }
#r3-ln    { grid-column: 5;  grid-row: 3; }
#r3-log   { grid-column: 6;  grid-row: 3; }
#r3-7     { grid-column: 7;  grid-row: 3; }
#r3-8     { grid-column: 8;  grid-row: 3; }
#r3-9     { grid-column: 9;  grid-row: 3; }
#r3-div   { grid-column: 10; grid-row: 3; }
#r3-pct   { grid-column: 11; grid-row: 3; }

/* ROW 4 */
#r4-pi    { grid-column: 1;  grid-row: 4; }
#r4-e     { grid-column: 2;  grid-row: 4; }
#r4-fact  { grid-column: 3;  grid-row: 4; }
#r4-logy  { grid-column: 4;  grid-row: 4; }
#r4-ex    { grid-column: 5;  grid-row: 4; }
#r4-10x   { grid-column: 6;  grid-row: 4; }
#r4-4     { grid-column: 7;  grid-row: 4; }
#r4-5     { grid-column: 8;  grid-row: 4; }
#r4-6     { grid-column: 9;  grid-row: 4; }
#r4-mul   { grid-column: 10; grid-row: 4; }
#r4-recip { grid-column: 11; grid-row: 4; }

/* ROW 5 */
#r5-sin { grid-column: 1;  grid-row: 5; }
#r5-cos { grid-column: 2;  grid-row: 5; }
#r5-tan { grid-column: 3;  grid-row: 5; }
#r5-pxy { grid-column: 4;  grid-row: 5; }
#r5-x3  { grid-column: 5;  grid-row: 5; }
#r5-x2  { grid-column: 6;  grid-row: 5; }
#r5-1   { grid-column: 7;  grid-row: 5; }
#r5-2   { grid-column: 8;  grid-row: 5; }
#r5-3   { grid-column: 9;  grid-row: 5; }
#r5-sub { grid-column: 10; grid-row: 5; }
#r5-eq  { grid-column: 11; grid-row: 5/7; }

/* ROW 6 */
#r6-asin  { grid-column: 1;   grid-row: 6; }
#r6-acos  { grid-column: 2;   grid-row: 6; }
#r6-atan  { grid-column: 3;   grid-row: 6; }
#r6-yroot { grid-column: 4;   grid-row: 6; }
#r6-cbrt  { grid-column: 5;   grid-row: 6; }
#r6-abs   { grid-column: 6;   grid-row: 6; }
#r6-0     { grid-column: 7/9; grid-row: 6; }
#r6-dot   { grid-column: 9;   grid-row: 6; }
#r6-add   { grid-column: 10;  grid-row: 6; }

/* ============================================================
   Help modal
   ============================================================ */
#help-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(3px);
  z-index: 999;
  justify-content: center;
  align-items: center;
}
#help-overlay.visible { display: flex; }

#help-box {
  background: #fff;
  border: 2px solid #4a90d9;
  border-radius: 8px;
  width: 530px;
  max-height: 82vh;
  overflow-y: auto;
  padding: 18px 22px;
  font-size: 13px;
  line-height: 1.65;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

#help-box h2 { color: #4a90d9; margin-bottom: 10px; font-size: 16px; }
#help-box h3 { color: #333; margin: 12px 0 4px; font-size: 13px; }

#help-box table { border-collapse: collapse; width: 100%; margin-bottom: 8px; }
#help-box td,
#help-box th   { border: 1px solid #ddd; padding: 4px 8px; text-align: left; }
#help-box th   { background: #e8f0fb; font-weight: bold; }

#help-box p { margin-top: 4px; }

#help-close {
  display: block;
  margin: 14px auto 0;
  background: #4a90d9;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 6px 28px;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 2px 0 #2a60b0;
}
#help-close:hover { background: #3a7abf; }
#help-close:active { transform: translateY(1px); box-shadow: 0 1px 0 #2a60b0; }

/* ============================================================
   Theme-name toast  (shown briefly when theme changes)
   ============================================================ */
#theme-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 13px;
  padding: 6px 20px;
  border-radius: 20px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
  z-index: 1000;
}
#theme-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   DRAGGABLE & RESIZABLE  —  positioning, cursor & touch rules
   ============================================================ */

/* The calculator becomes a freely-positioned floating window. */
#calculator {
  position: fixed;
  min-width:  320px;   /* comfortable on phones */
  min-height: 260px;
  /* overflow:visible and display:flex set in main rule above */
}

/* ── Title bar drag zone ── */
#titlebar {
  cursor: grab;
  /* Prevent the browser from hijacking the touch gesture
     (scroll / pan) while the user is dragging the calculator. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#titlebar.dragging {
  cursor: grabbing;
}

/* Keep display clipped */
#display-area { overflow: hidden; }

/* ── Resize handles ──
   Edge handles: 22 px wide/tall so a fingertip can grab them.
   Corner handles: 28 × 28 px — large enough for touch.
   All handles get touch-action:none so the browser doesn't
   scroll the page during a resize gesture.                    */
.resize-handle {
  position: absolute;
  z-index: 10;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* North */
.resize-n  { top: -11px; left: 20px; right: 20px; height: 22px; cursor: n-resize; }
/* South */
.resize-s  { bottom: -11px; left: 20px; right: 20px; height: 22px; cursor: s-resize; }
/* East */
.resize-e  { right: -11px; top: 20px; bottom: 20px; width: 22px; cursor: e-resize; }
/* West */
.resize-w  { left: -11px; top: 20px; bottom: 20px; width: 22px; cursor: w-resize; }
/* NW */
.resize-nw { top: -11px; left: -11px; width: 28px; height: 28px; cursor: nw-resize; }
/* NE */
.resize-ne { top: -11px; right: -11px; width: 28px; height: 28px; cursor: ne-resize; }
/* SW */
.resize-sw { bottom: -11px; left: -11px; width: 28px; height: 28px; cursor: sw-resize; }
/* SE */
.resize-se { bottom: -11px; right: -11px; width: 28px; height: 28px; cursor: se-resize; }

/* Corner accent: L-shaped bracket visible on all themes */
.resize-nw::before, .resize-ne::before,
.resize-sw::before, .resize-se::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border-color: rgba(255,255,255,0.5);
  border-style: solid;
}
.resize-nw::before { top: 5px;    left: 5px;   border-width: 2px 0 0 2px; }
.resize-ne::before { top: 5px;    right: 5px;  border-width: 2px 2px 0 0; }
.resize-sw::before { bottom: 5px; left: 5px;   border-width: 0 0 2px 2px; }
.resize-se::before { bottom: 5px; right: 5px;  border-width: 0 2px 2px 0; }

/* While resizing: suppress pointer events on content to prevent
   accidental button triggers and cursor flicker.               */
body.resizing * { pointer-events: none !important; }
body.resizing .resize-handle { pointer-events: all !important; }

/* While dragging: lock cursor on entire page */
body.calc-dragging { cursor: grabbing !important; }
body.calc-dragging * { pointer-events: none !important; cursor: grabbing !important; }

/* ============================================================
   MOBILE / COARSE-POINTER OVERRIDES
   Applied when the primary input is a finger (touchscreen).
   ============================================================ */
@media (pointer: coarse) {

  /* Bigger title / buttons in titlebar so they're easier to tap */
  #titlebar { padding: 8px 10px; }
  #titlebar .title { font-size: 16px; }

  #btn-help,
  #btn-theme { padding: 6px 14px; font-size: 14px; }

  .win-btn { width: 30px; height: 28px; font-size: 13px; }

  /* Thicker edge handles — a 44 px target is Apple's HIG minimum */
  .resize-n,
  .resize-s  { height: 32px; top: auto; bottom: auto; }
  .resize-n  { top: -16px; }
  .resize-s  { bottom: -16px; }

  .resize-e,
  .resize-w  { width: 32px; }
  .resize-e  { right: -16px; }
  .resize-w  { left: -16px; }

  .resize-nw,
  .resize-ne,
  .resize-sw,
  .resize-se { width: 40px; height: 40px; }
  .resize-nw { top: -16px; left: -16px; }
  .resize-ne { top: -16px; right: -16px; }
  .resize-sw { bottom: -16px; left: -16px; }
  .resize-se { bottom: -16px; right: -16px; }

  /* Corner bracket bigger too */
  .resize-nw::before, .resize-ne::before,
  .resize-sw::before, .resize-se::before {
    width: 18px; height: 18px;
  }

  /* Buttons: slightly more padding, larger tap area */
  .btn { border-radius: 6px; }

  /* Help box full-width on small phones */
  #help-box { width: 92vw; padding: 14px 16px; }
}

/* Very small screens: start narrower, let calc fill the screen */
@media (max-width: 480px) {
  #calculator { min-width: 280px; }
}
