:root {
  --frame: #1b1c20;
  --bar: #2a2c32;
  --field: #1b1c20;
  --hover: #383a42;
  --line: #3a3c44;
  --text: #ececef;
  --muted: #a3a5ad;
  --accent: #4f7df0;
  --accent-text: #ffffff;
  --danger: #ff8a80;
  --radius: 8px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--frame);
  color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
}

button, input, select { font: inherit; color: inherit; }

/* ------------------------------------------------------------ browser UI */

.app {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100dvh;
}

.chrome { flex: none; user-select: none; }

.tabbar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px 8px 0;
  background: var(--frame);
}

.tablist {
  display: flex;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tablist::-webkit-scrollbar { display: none; }

.tab {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 1 200px;
  min-width: 96px;
  height: 32px;
  padding: 0 6px 0 12px;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { background: #24262b; }
.tab.active { background: var(--bar); color: var(--text); }

.tab-label {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
}

.tab-close {
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  line-height: 1;
  cursor: pointer;
}
.tab-close:hover { background: var(--hover); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tabbar .icon-btn { width: 28px; height: 28px; margin-bottom: 2px; }

.urlform { flex: 1; min-width: 0; margin: 0 4px; }

.url {
  width: 100%;
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 17px;
  background: var(--field);
  outline: none;
  font-size: 16px; /* iOS がフォーカス時に拡大しないように */
}
.url:focus { border-color: var(--accent); }

.quality {
  flex: none;
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
}

.stats {
  flex: none;
  min-width: 84px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.logout { margin: 0; }

.text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.text-btn:hover { background: var(--hover); color: var(--text); }
.text-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#sound .sound-off { display: none; }
#sound[aria-pressed="false"] .sound-on { display: none; }
#sound[aria-pressed="false"] .sound-off { display: block; color: var(--muted); }

.touch-only { display: none; }
body.touch .touch-only { display: grid; }

@media (max-width: 640px) {
  .stats, .text-btn-label, #forward { display: none; }
  .text-btn { padding: 0 6px; }
  .toolbar { gap: 2px; padding: 6px 4px; }
  .urlform { margin: 0 2px; }
}

/* ---------------------------------------------------------------- screen */

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #111214;
}

.canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  outline: none;
  touch-action: none;
  cursor: default;
}

/* 文字入力を受け取る見えない欄。日本語の変換中だけ表示する。 */
.kbd {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  height: 2px;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  overflow: hidden;
  font-size: 16px;
  pointer-events: none;
}
.kbd.composing {
  z-index: 5;
  width: 18em;
  height: 2em;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: #fff;
  color: #111;
  opacity: 1;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.35);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: rgb(17 18 20 / 0.82);
}
.overlay[hidden] { display: none; }

.overlay-card {
  max-width: 340px;
  padding: 20px 24px;
  border-radius: 12px;
  background: var(--bar);
  text-align: center;
}
.overlay-card p { margin: 0; }
.overlay-card button { margin-top: 14px; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 20px;
  z-index: 11;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: #f1f1f3;
  color: #16171a;
  transform: translateX(-50%);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.3);
}
.toast[hidden] { display: none; }

.primary-btn {
  height: 38px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.08); }

/* ----------------------------------------------------------------- login */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.login-card {
  width: min(100%, 360px);
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bar);
}

.login-icon { display: block; margin-bottom: 14px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-sub { margin: 0 0 22px; color: var(--muted); }

.login-form { display: grid; gap: 8px; }
.login-form label { color: var(--muted); font-size: 13px; }
.login-form input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  font-size: 16px;
  outline: none;
}
.login-form input:focus { border-color: var(--accent); }
.login-form input.pin-input {
  height: 52px;
  font-size: 28px;
  letter-spacing: 0.6em;
  text-align: center;
  padding-left: 0.6em; /* letter-spacing の分だけ中央に寄せる */
}
.login-form button { margin-top: 10px; }
.login-error { margin: 2px 0 0; color: var(--danger); font-size: 13px; }
