* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #ffffff;
  color: #171717;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.page > * + * {
  margin-top: 16px;
}

.page h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.1;
  width: 560px;
  max-width: calc(100vw - 48px);
  text-align: left;
}

.page p {
  margin: 0;
  font-size: 14px;
  color: #52525c;
}

.game-shell {
  width: 560px;
  max-width: calc(100vw - 48px);
}

.toolbar {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  width: 360px;
  max-width: 100%;
}

.toolbar > * + * {
  margin-left: 8px;
}

.toolbar label {
  font-size: 14px;
  font-weight: 700;
}
.difficulty_select_wrap,
#generate_button {
  height: 32px;
  border: 1px solid #000;
  font-size: 14px;
  background: #fff;
}

.difficulty_select_wrap {
  position: relative;
  display: inline-block;
  min-width: 132px;
  background: #fff;
  overflow: hidden;
}

.difficulty_select_wrap:focus-within {
  outline: 2px solid #000;
  outline-offset: 0;
}

#difficulty_select {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  padding: 0 30px 0 10px;
  font-size: 14px;
  font-weight: 400;
  color: #111;
  background: transparent;
  font-family: inherit;
  line-height: normal;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

#difficulty_select:focus {
  outline: none;
}

#difficulty_select::-ms-expand {
  display: none;
}

.select_caret {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 12px;
  margin-top: -5px;
  color: #111;
  font-size: 11px;
  line-height: 1;
  text-align: center;
  pointer-events: none;
}

#generate_button {
  height: 32px;
  border: 1px solid #000;
  font-size: 14px;
  padding: 0 10px;
  background: #efefef;
  color: #000;
  font-weight: 700;
  cursor: pointer;
  margin-left: 0;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

.toolbar_actions {
  margin-left: auto;
  display: flex;
}

.toolbar_actions > * + * {
  margin-left: 8px;
}

#correct_button,
#tip_button,
#tip_modal_close {
  height: 32px;
  border: 1px solid #000;
  font-size: 14px;
  padding: 0 10px;
  background: #efefef;
  color: #000;
  font-weight: 700;
  cursor: pointer;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

.board_and_controls {
  display: flex;
  align-items: flex-start;
}

.board_and_controls > * + * {
  margin-left: 8px;
}

.board {
  position: relative;
  width: 360px;
  height: 360px;
}

.controls_panel {
  display: flex;
}

.controls_panel > * + * {
  margin-left: 8px;
}

.mode_column {
  display: flex;
  flex-direction: column;
}

.mode_column > * + * {
  margin-top: 8px;
}

.mode_column .mode_button[data-mode] + .mode_button[data-mode] {
  margin-top: -1px;
}

.mode_column .mode_button[data-action="undo"] {
  margin-top: 18px;
}

.mode_column .mode_button[data-action="redo"] {
  margin-top: -1px;
}

.digit_column {
  display: flex;
  flex-direction: column;
  width: 40px;
  height: 360px;
}

.digit_column.clear_mode {
  opacity: 0.25;
}

.mode_button {
  min-height: 46px;
  border: 1px solid #000;
  background: #efefef;
  color: #000;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  cursor: pointer;
  user-select: none;
}

.mode_button_content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  line-height: 1;
}

.mode_button_icon {
  display: block;
  min-height: 1em;
  font-size: 1.15em;
  line-height: 1;
  white-space: nowrap;
}

.mode_button_label {
  display: block;
  margin-top: 0.22em;
  font-size: 0.76em;
  line-height: 1;
  white-space: nowrap;
}

.mode_button[data-mode="insert"] .mode_button_icon {
  letter-spacing: 0.03em;
}

.mode_button[data-mode="center"] .mode_button_icon {
  letter-spacing: 0.03em;
}

.mode_button.active {
  background: #000;
  color: #fff;
}

.mode_button:not(.disabled):hover {
  background: #e5e5e5;
}

.mode_button.active:not(.disabled):hover {
  background: #111111;
}

.mode_button.undo_divider {
  position: relative;
  margin-top: 8px;
}

.mode_button.undo_divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -10px;
  height: 2px;
  background: #bbb;
}

.mode_button.disabled,
.digit_button.disabled {
  opacity: 0.25;
  pointer-events: none;
}

.digit_button {
  width: 40px;
  height: 40px;
  border: 1px solid #000;
  border-bottom-width: 0;
  background: #efefef;
  color: #000;
  font-size: 28px;
  font-weight: 700;
  line-height: 40px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.digit_button:last-child {
  border-bottom-width: 1px;
}

.digit_button.active {
  background: #000;
  color: #fff;
}

.digit_button:not(.disabled):hover {
  background: #e5e5e5;
}

.digit_button.active:not(.disabled):hover {
  background: #111111;
}

.cell {
  position: absolute;
  width: 40px;
  height: 40px;
  text-align: center;
  font-size: 20px;
  cursor: pointer;
  user-select: none;
  border: 1px solid #777;
  background: #ffffff;
  font-weight: 400;
}

.cell[data-state="given"] {
  background: #f4f4f5;
  font-weight: 700;
}

.cell[data-state="selected"] {
  background: #fde68a;
  outline: 3px dashed #000;
  outline-offset: -3px;
  z-index: 3;
}

.cell[data-state="selected"][data-given="true"] {
  font-weight: 700;
  background: #ececef;
  outline: 3px dashed #444;
  outline-offset: -3px;
}

.cell[data-given="false"]:not([data-state="selected"]):hover {
  background: #f7f7f7;
}

.cell[data-state="selected"][data-given="false"]:hover {
  background: #fcd34d;
}

.cell.multi_selected {
  background: #fef3c7;
}

.cell.multi_selected[data-given="true"] {
  background: #efeff1;
  outline: 2px dashed #888;
  outline-offset: -2px;
}

.cell.multi_selected[data-given="false"]:hover {
  background: #fde68a;
}

.cell.invalid_mark .cell_value {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: #7f1d1d;
  color: #7f1d1d;
}

.cell_value {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  line-height: 40px;
  font-size: 30px;
}

.cell_corner_mark {
  position: absolute;
  font-size: 10px;
  line-height: 1;
  color: #3f3f46;
  width: 10px;
  height: 10px;
  text-align: center;
}

.cell_center {
  position: absolute;
  left: 2px;
  right: 2px;
  top: 50%;
  transform: translateY(-45%);
  text-align: center;
  font-size: 10px;
  line-height: 1;
  letter-spacing: -1.5px;
  color: #52525c;
  min-height: 10px;
  white-space: nowrap;
}

.corner_pos_1 {
  top: 2px;
  left: 2px;
}

.corner_pos_2 {
  top: 2px;
  left: 14px;
}

.corner_pos_3 {
  top: 2px;
  right: 2px;
}

.corner_pos_4 {
  top: 14px;
  left: 2px;
}

.corner_pos_5 {
  top: 14px;
  right: 2px;
}

.corner_pos_6 {
  bottom: 2px;
  left: 2px;
}

.corner_pos_7 {
  bottom: 2px;
  left: 14px;
}

.corner_pos_8 {
  bottom: 2px;
  right: 2px;
}

.cell.thick-top {
  border-top-width: 2px;
  border-top-color: #666;
}

.cell.thick-left {
  border-left-width: 2px;
  border-left-color: #666;
}

.cell.thick-bottom {
  border-bottom-width: 2px;
  border-bottom-color: #666;
}

.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #111;
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
  padding: 9px 12px;
  border: 1px solid #000;
  max-width: min(320px, calc(100vw - 16px));
  opacity: 0;
  pointer-events: none;
}

.toast.anchored {
  transform: none;
}

.toast.visible {
  opacity: 0.97;
}

.toast .toast_content {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.toast .toast_icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  flex: 0 0 16px;
  margin-top: 1px;
}

.toast .toast_icon svg {
  width: 16px;
  height: 16px;
}

.toast .toast_message {
  font-weight: 600;
}

.toast.ok,
.toast.info,
.toast.not_ok {
  background: #fff;
  color: #111;
}

.toast.ok {
  border: 2px solid #1a5a1a;
}

.toast.ok .toast_icon {
  color: #1a5a1a;
}

.toast.not_ok {
  border: 2px solid #8f1f1f;
}

.toast.not_ok .toast_icon {
  color: #8f1f1f;
}

.toast.info {
  border: 2px solid #444;
}

.toast.info .toast_icon {
  color: #222;
}

.tip_modal {
  position: fixed;
  left: 0;
  right: 0;
  top: 50%;
  bottom: 0;
  z-index: 50;
  background: #fff;
  border-top: 2px solid #000;
  padding: 12px;
  display: none;
  overflow: auto;
}

.tip_modal.visible {
  display: block;
}

.tip_modal_header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

#tip_modal_content {
  margin: 0;
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

@media (max-width: 560px) {
  .page {
    padding: 8px;
  }

  .game-shell {
    width: 360px;
    max-width: calc(100vw - 16px);
  }

  .page h1 {
    width: 360px;
    max-width: calc(100vw - 16px);
  }

  .toolbar {
    width: 360px;
  }

  .difficulty_select_wrap {
    min-width: 0;
  }

  .board_and_controls {
    flex-direction: column;
  }

  .board_and_controls > * + * {
    margin-left: 0;
    margin-top: 8px;
  }

  .controls_panel {
    width: 360px;
    flex-direction: column;
  }

  .controls_panel > * + * {
    margin-left: 0;
    margin-top: 8px;
  }

  .mode_column {
    width: 360px;
    display: flex;
    flex-direction: row;
    align-items: stretch;
  }

  .mode_column > * {
    flex: 1 1 0;
    width: auto;
  }

  .mode_column > * + * {
    margin-top: 0;
    margin-left: 4px;
  }

  .mode_column .mode_button[data-mode] + .mode_button[data-mode] {
    margin-top: 0;
    margin-left: -1px;
  }

  .mode_column .mode_button[data-action="undo"] {
    margin-top: 0;
    margin-left: 12px;
    border-right-width: 0;
  }

  .mode_column .mode_button[data-action="redo"] {
    margin-top: 0;
    margin-left: 0;
  }

  .mode_button {
    min-height: 56px;
    height: 56px;
    font-size: 10px;
    padding: 6px 4px;
    box-sizing: border-box;
  }

  .mode_button_icon {
    font-size: 1.38em;
  }

  .mode_button_label {
    margin-top: 0.28em;
    font-size: 0.86em;
  }

  .mode_button.undo_divider {
    margin-top: 0;
  }

  .mode_button.undo_divider::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -8px;
    width: 2px;
    height: auto;
    background: #bbb;
  }

  .digit_column {
    width: 360px;
    height: 40px;
    flex-direction: row;
  }

  .digit_button {
    border-right-width: 0;
    border-bottom-width: 1px;
  }

  .digit_button:last-child {
    border-right-width: 1px;
  }
}

.cell.thick-right {
  border-right-width: 2px;
  border-right-color: #666;
}
