:root {
  --bg: #f3efea;
  --surface: #ffffff;
  --surface-2: #faf7f3;
  --cell-bg: #ffffff;
  --text: #2c2521;
  --muted: #5a4a3a;
  --heading: #7a3b10;
  --border: #8a7a68;
  --accent: #8a5a00;
  --accent-text: #ffffff;
  --link: #7a4e00;
  --coord: #7a3b10;
  --coord-text: #ffffff;
  --used: #f2d675;
  --used-text: #4a2506;
  --ok: #1d6b36;
  --ok-text: #ffffff;
  --warn: #8a4b00;
  --err: #a3261c;
  --shadow: rgba(0, 0, 0, 0.1);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic",
    "Noto Sans JP", "Noto Sans CJK JP", Meiryo, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15110d;
    --surface: #211b15;
    --surface-2: #2b241c;
    --cell-bg: #2b241c;
    --text: #f3ece4;
    --muted: #c9bba9;
    --heading: #e9b872;
    --border: #8f7f6c;
    --accent: #e0b64a;
    --accent-text: #1d1503;
    --link: #e9c46a;
    --coord: #6b3512;
    --coord-text: #ffffff;
    --used: #e0b64a;
    --used-text: #1d1503;
    --ok: #7bd69a;
    --ok-text: #08210f;
    --warn: #f0b86a;
    --err: #ff9d92;
  }
}

:root[data-theme="dark"] {
  --bg: #15110d;
  --surface: #211b15;
  --surface-2: #2b241c;
  --cell-bg: #2b241c;
  --text: #f3ece4;
  --muted: #c9bba9;
  --heading: #e9b872;
  --border: #8f7f6c;
  --accent: #e0b64a;
  --accent-text: #1d1503;
  --link: #e9c46a;
  --coord: #6b3512;
  --coord-text: #ffffff;
  --used: #e0b64a;
  --used-text: #1d1503;
  --ok: #7bd69a;
  --ok-text: #08210f;
  --warn: #f0b86a;
  --err: #ff9d92;
}


* { box-sizing: border-box; }

body {
  font-family: var(--font);
  max-width: 1180px;
  margin: auto;
  padding: 1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
}

h1 {
  text-align: center;
  color: var(--heading);
  font-weight: 700;
  font-size: 1.5rem;
  margin-bottom: 1rem;
  text-shadow: 0 2px 4px var(--shadow);
}

h1::after {
  content: '';
  display: block;
  width: 80px;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--heading));
  margin: 1rem auto;
  border-radius: 2px;
}

.input-section {
  background: var(--surface);
  padding: 0.8rem;
  border-radius: 12px;
  box-shadow: 0 4px 15px var(--shadow);
  margin-bottom: 0.8rem;
  border: 1px solid var(--border);
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--muted);
}

textarea {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
  resize: vertical;
  font-family: var(--font);
}

textarea:focus {
  outline: 3px solid var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--shadow);
}

.controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.mode-toggle {
  background: var(--surface);
  padding: 0.8rem;
  border-radius: 12px;
  box-shadow: 0 4px 15px var(--shadow);
  border: 1px solid var(--border);
}

.mode-toggle legend {
  color: var(--heading);
  font-weight: 500;
  display: block;
  margin-bottom: 1rem;
}

.mode-toggle label {
  display: flex;
  align-items: center;
  margin-bottom: 0.8rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.mode-toggle label:hover {
  background-color: var(--surface-2);
}

input[type="radio"] {
  margin-right: 0.8rem;
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.execute-btn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px var(--shadow);
  margin-bottom: 2rem;
  font-family: var(--font);
}

.execute-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--shadow);
}

.table-container {
  background: var(--surface);
  padding: 0.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 15px var(--shadow);
  margin-bottom: 2rem;
  border: 1px solid var(--border);
}

table {
  border-collapse: separate;
  border-spacing: 2px;
  margin: 0 auto;
  background: var(--surface-2);
  border-radius: 8px;
  overflow: hidden;
}

th, td {
  padding: 0.15rem;
  text-align: center;
  width: 12.5%;
  height: clamp(2.25rem, 4vw, 3.5rem);
}

.char-cell {
  font-size: 1.15rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  transition: all 0.2s ease;
}

.char-cell:hover {
  background: var(--surface-2);
  transform: scale(1.05);
  box-shadow: 0 2px 8px var(--shadow);
}

.char-cell.used {
  background: var(--used);
  color: var(--heading);
  font-weight: 700;
  transform: scale(1.05);
  box-shadow: 0 3px 10px var(--shadow);
  border: 2px solid var(--accent);
  animation: highlight-pulse 1s ease-in-out;
}

@keyframes highlight-pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1.05); }
}

.char-cell.used:hover {
  background: var(--used);
  transform: scale(1.1);
}

.coord-cell {
  font-size: 1rem;
  color: var(--coord-text);
  background: var(--coord);
  font-weight: 500;
  border-radius: 6px;
  text-shadow: 0 1px 2px var(--shadow);
}

.result-section {
  background: var(--surface);
  padding: 0.8rem;
  border-radius: 12px;
  box-shadow: 0 4px 15px var(--shadow);
  border: 1px solid var(--border);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.result-header h2 {
  margin: 0;
  color: var(--heading);
  font-weight: 500;
}

.result-message {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: var(--surface-2);
  border-radius: 6px;
  display: none;
}

.result-message.show {
  display: block;
}

.copy-btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px var(--shadow);
  font-family: var(--font);
}

.copy-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--shadow);
}

.copy-btn:disabled {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: not-allowed;
}

.copy-btn.success {
  background: var(--ok);
  color: var(--ok-text);
}

.output-area {
  background: var(--surface);
  padding: 0.8rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  font-size: 1.1rem;
  line-height: 1.8;
  color: var(--text);
  box-shadow: inset 0 2px 4px var(--shadow);
  min-height: 80px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font);
}

.divider {
  margin: 1.5rem auto;
  width: 60%;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 20%, var(--heading) 50%, var(--accent) 80%, transparent 100%);
  position: relative;
}

.divider::before {
  content: '◆';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  color: var(--heading);
  font-size: 1.2rem;
  padding: 0.5rem;
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.footer {
  text-align: center;
  margin-top: 0;
  padding: 0.8rem;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 4px 15px var(--shadow);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.95rem;
}

.footer a {
  color: var(--link);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
}

.footer a:hover {
  color: var(--link);
  text-decoration: underline;
}


/* 入力→設定→結果→表の順序を維持して、広い画面だけ2カラムにする。 */
header {
  position: relative;
}

h1 {
  margin: 0.4rem 0 1rem;
}

h2 {
  font-size: 1.2rem;
  color: var(--heading);
  margin: 0 0 0.5rem;
}

/* 言語とテーマのボタンは横並びにして、狭い画面でも見出しに重ねない。 */
.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.theme-toggle, .lang-toggle {
  min-height: 44px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.theme-toggle {
  width: 44px;
  height: 44px;
}

.lang-toggle {
  padding: 0 0.75rem;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}

.app {
  display: grid;
  gap: 1rem;
  align-items: start;
}

.work-area, .table-container, fieldset {
  min-width: 0;
}

.mode-toggle {
  margin: 0;
  padding: 0.5rem 0.65rem;
}

.mode-toggle legend {
  margin: 0;
}

.mode-toggle label {
  min-height: 44px;
  margin: 0;
  padding: 0.25rem;
}

.key-settings {
  margin-bottom: 0.8rem;
}

.key-inputs {
  display: grid;
  gap: 0.5rem;
}

.key-inputs input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem;
}

.key-message {
  margin: 0.2rem 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 0.875rem;
}

.key-message.error {
  color: var(--err);
  background: var(--surface-2);
}

.key-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.input-hint {
  font-size: 0.875rem;
  color: var(--muted);
  margin: 0.4rem 0 0;
}

button {
  min-height: 44px;
  font-family: var(--font);
}

button:disabled {
  cursor: not-allowed;
}

.execute-btn {
  margin-bottom: 0.8rem;
}

.result-header {
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.result-header h2 {
  margin-right: auto;
}

.result-message {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-2);
}

.result-message.warning {
  color: var(--warn);
}

.result-message.error {
  color: var(--err);
}

.output-area {
  background: var(--surface-2);
  padding: 0.8rem;
}

table {
  width: 100%;
  table-layout: fixed;
}

caption {
  color: var(--heading);
  font-weight: 700;
  padding-bottom: 0.6rem;
}

.char-cell {
  background: var(--cell-bg);
}

.char-cell.used {
  color: var(--used-text);
  transform: none;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

@media (min-width: 600px) {
  .controls .mode-toggle label {
    display: inline-flex;
  }

  .controls, .key-inputs {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
  }

  .key-modes {
    display: flex;
    flex-wrap: wrap;
  }

  h1 {
    font-size: 2rem;
  }
}

@media (min-width: 1024px) {
  .app {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  }

  .table-container {
    padding: 1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }

  .char-cell:hover, .char-cell.used:hover, button:hover {
    transform: none;
  }
}
