:root {
  /* Light theme */
  --bg: #ffffff;            /* page background (surrounding) */
  --panel: #ffffff;         /* inner panels */
  --text: #0b1020;          /* main text */
  --muted: #475569;         /* subdued text */
  --accent: #2563eb;        /* blue accents */
  --success: #1db954;
  --error: #ff4d4f;
  --warning: #ffb020;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  position: relative; /* to anchor the timer */
  max-width: 760px;
  margin: 4rem auto;
  padding: 2rem;
  background: #dbeafe; /* light blue stopwatch area */
  border: 1px solid #93c5fd;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}

.title { margin-top: 0; text-align: center; letter-spacing: 0.3px; }

.display { display: grid; gap: 1rem; }
.euler-line {
  position: relative;          /* allow prefix overlay */
  display: block;
  padding: clamp(0.6rem, 1.2vw, 1.0rem) clamp(0.8rem, 1.8vw, 1.4rem); /* tighter padding */
  background: var(--panel);
  border: 1px solid #bfdbfe; /* lighter blue border */
  border-radius: 12px;
  width: 100%;               /* fill card width */
  min-height: 120px;         /* ensure minimum height for content */
}

/* Prefix is now its own row */
.euler-prefix-row {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: clamp(1.0rem, 3.2vw, 2.0rem); /* more conservative scaling to match input */
  line-height: 1.1;
  color: var(--muted);
  text-align: center;
  margin-bottom: clamp(0.1rem, 0.6vw, 0.4rem); /* tighter spacing */
}

.euler-input {
  display: block;
  width: min(100%, calc(25ch + 8px)); /* fit exactly 25ch + padding without overflow */
  margin: 0 auto;                      /* center in white field */
  background: transparent;
  border: none;
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: clamp(0.6rem, 3.8vw, 2.2rem); /* more conservative scaling */
  line-height: 1.1;                       /* very tight to ensure 4 rows always fit */
  outline: none;
  caret-color: var(--accent);
  resize: none;
  white-space: pre;              /* we insert newlines */
  box-sizing: border-box;
  padding: 2px 4px;              /* minimal padding to stay within bounds */
  height: calc(1.1em * 4 + 6px); /* tight height calculation for 4 rows */
  text-align: center;            /* center digits */
  overflow: hidden;              /* prevent any scrolling */
  max-width: 100%;               /* never exceed container width */
}

/* Force smaller font on very narrow screens to ensure 25 digits always fit per row */
@media (max-width: 480px) {
  .euler-input {
    font-size: clamp(0.5rem, 2.8vw, 1.2rem) !important;
    line-height: 1.05 !important;
    height: calc(1.05em * 4 + 4px) !important;
  }
  .euler-prefix-row {
    font-size: clamp(0.7rem, 2.5vw, 1.4rem) !important;
  }
}

/* Even smaller for very narrow screens */
@media (max-width: 360px) {
  .euler-input {
    font-size: clamp(0.45rem, 2.2vw, 1.0rem) !important;
    line-height: 1.0 !important;
    height: calc(1.0em * 4 + 3px) !important;
    padding: 1px 2px !important;
  }
  .euler-prefix-row {
    font-size: clamp(0.6rem, 2.0vw, 1.2rem) !important;
    margin-bottom: 0.1rem !important;
  }
}
.euler-input::placeholder { color: #6b7596; text-align: center; }

/* Timer positioned top-right of blue card */
.app .timer {
  position: absolute !important;
  top: 0.75rem;
  right: 0.9rem;
  text-align: right;
  z-index: 5;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" on;
  font-weight: 800;
  font-size: clamp(0.95rem, 2.2vw, 1.4rem); /* smaller */
  letter-spacing: 0.4px;
}

.status {
  text-align: center;
  min-height: 2rem;
  font-weight: 700;
}

.controls { display: flex; justify-content: center; }
.btn {
  padding: 0.45rem 0.8rem; /* reduced size */
  background: #1a2656;
  color: #ffffff; /* ensure reset text is white */
  border: 1px solid #24357d;
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover { background: #21306f; }

.flash-success { animation: flashSuccess 0.8s ease-in-out 0s 2; }
.flash-error { animation: flashError 0.6s ease-in-out 0s 3; }

@keyframes flashSuccess {
  0%, 100% { box-shadow: 0 0 0 0 rgba(29,185,84,0); }
  50% { box-shadow: 0 0 0 6px rgba(29,185,84,0.35); }
}

@keyframes flashError {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,77,79,0); }
  50% { box-shadow: 0 0 0 6px rgba(255,77,79,0.4); }
}

.success-text { color: var(--success); }
.error-text { color: var(--error); }

.help { margin-top: 1rem; color: var(--muted); }
.help code { color: var(--text); word-break: break-all; }
