* { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --text: #222222;
  --muted: #999999;
  --border: #dddddd;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-press: #f0f0f0;
  --modal-bg: #ffffff;
  --input-bg: #fcfcfc;
  --input-border: #e0e0e0;
  --btn-bg: #f2f2f2;
  --btn-text: #666666;
  --accent: #2a6fd6;
  --accent-press: #245cb2;
  --accent-disabled: #b9cdec;
  --link: #2a6fd6;
  --center-bg: #ffffff;
  --center-stroke: #cccccc;
  --center-glyph: #999999;
  --shadow: rgba(0, 0, 0, 0.12);
}
body.dark {
  --bg: #131316;
  --text: #e4e4e7;
  --muted: #8a8a90;
  --border: #3a3a40;
  --surface: rgba(30, 30, 34, 0.92);
  --surface-press: #2c2c31;
  --modal-bg: #1e1e22;
  --input-bg: #26262b;
  --input-border: #3a3a40;
  --btn-bg: #2c2c31;
  --btn-text: #b0b0b6;
  --accent: #4d8dee;
  --accent-press: #3a76d2;
  --accent-disabled: #2e405e;
  --link: #6ea8ff;
  --center-bg: #1e1e22;
  --center-stroke: #44444c;
  --center-glyph: #8a8a90;
  --shadow: rgba(0, 0, 0, 0.5);
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#wheelSvg {
  width: 100%;
  height: 100%;
  display: block;
}

.cell { cursor: pointer; }
.cell:focus:not(:focus-visible), #center:focus:not(:focus-visible) { outline: none; }
.cell path.base { transition: fill 150ms, stroke 150ms; }
.cell path.shade { pointer-events: none; }
.cell text { pointer-events: none; }

#center { cursor: pointer; }
#center circle { fill: var(--center-bg); stroke: var(--center-stroke); }
#centerGlyph { fill: var(--center-glyph); opacity: 0; transition: opacity 200ms; pointer-events: none; }
#center.active #centerGlyph { opacity: 1; }

/* Corner buttons */
.corner {
  position: fixed;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--btn-text);
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  box-shadow: 0 1px 4px var(--shadow);
}
.corner:active { background: var(--surface-press); }
.top-right { top: calc(env(safe-area-inset-top, 0px) + 12px); right: 12px; }
.bottom-right { bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); right: 12px; }

/* Modals */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
body.dark .backdrop { background: rgba(0, 0, 0, 0.55); }
.backdrop[hidden] { display: none; }

.modal {
  position: relative;
  background: var(--modal-bg);
  border-radius: 14px;
  padding: 20px 22px;
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-user-select: text;
  user-select: text;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
}
.modal.wide { max-width: 720px; padding: 18px 10px; }
.modal.wide h2 { padding-left: 6px; }
.modal.wide h3 { padding-left: 6px; }
.modal h2 { margin: 0 0 10px; font-size: 20px; }
.modal h3 { margin: 18px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.modal .close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 15px;
  cursor: pointer;
}
.howto { margin: 0; padding-left: 18px; }
.howto li { margin: 6px 0; font-size: 14.5px; line-height: 1.45; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.about { font-size: 13.5px; line-height: 1.5; color: var(--text); opacity: 0.85; }
.about a { color: var(--link); }

.setting { margin: 12px 0; }
.setting label { display: block; font-size: 14.5px; margin-bottom: 6px; }
.setting.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting.row label { margin: 0; }
.setting input[type="range"] { width: 100%; }
.setting select {
  font-size: 14.5px;
  padding: 4px 8px;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--input-border);
  border-radius: 6px;
}

/* Summary table */
#summaryTable {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
  font-size: 14px;
}
#summaryTable td { padding: 8px 3px; border-bottom: 1px solid var(--input-border); vertical-align: top; }
#summaryTable td:first-child { padding-left: 6px; }
#summaryTable td:last-child { padding-right: 6px; }
#summaryTable td.nameCell { width: 36%; }
#summaryTable td.intCell { width: 44px; padding-left: 0; padding-right: 0; }
.feelChip {
  display: inline-block;
  max-width: 100%;
  padding: 4px 9px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  color: #2b2b2b;
  font-weight: 600;
  overflow-wrap: break-word;
}
.feelPath { font-size: 11.5px; color: var(--muted); margin-top: 4px; overflow-wrap: break-word; }
.stepper { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stepper button {
  width: 28px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}
.intVal { min-width: 26px; text-align: center; font-weight: 600; }
.thoughtInput {
  width: 100%;
  min-height: 38px;
  max-height: 420px;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  resize: none;          /* height is managed by auto-grow */
  overflow-y: auto;
  background: var(--input-bg);
  color: var(--text);
}

.modal-actions { display: flex; gap: 10px; margin-top: 14px; justify-content: flex-end; }

/* Sessions */
.sessionSave {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 2px 0 8px 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.sessionSave[disabled] { opacity: 0.45; cursor: default; }
#sessionList { list-style: none; margin: 0; padding: 0; }
#sessionEmpty { padding-left: 6px; }
.sessionRow {
  display: flex;
  align-items: stretch;
  gap: 6px;
  border-bottom: 1px solid var(--input-border);
}
.sessLoad {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 9px 6px;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  border-radius: 8px;
}
.sessLoad:hover { background: var(--btn-bg); }
.sessName { font-size: 14.5px; font-weight: 600; }
.sessMeta { font-size: 11.5px; color: var(--muted); }
.sessDel {
  align-self: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.sessDel:hover { background: var(--btn-bg); color: var(--text); }
.action {
  width: 46px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.action:active { background: var(--accent-press); }
.action[disabled] { background: var(--accent-disabled); cursor: default; }

#toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 70px);
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13.5px;
  z-index: 50;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
body.dark #toast { background: #e4e4e7; color: #1a1a1e; }
